tags:

views:

26

answers:

2

I am building a web app that takes several tiff image files and merges them together into one single tiff image file using GNUWin32 tiffcp.exe from command line.

The way I was doing it was to loop through the file list and build a string of file names to merge into one single variable.

strfileList = "c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dvv.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-axs.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dxzs.tif"

Then I would just write to the command line:

tiffcp.exe strFileList results.tif

The file names are guids and so the paths are fairly long and I do not have any control to shorten them. So if I have a bunch of these documents (over 20 files or so), the length of the string variable exceeds the limits for windows command line and the merge fails.

Since this process is just merging files, my next thought was instead of writing the file names to a string, just do the merge one file at a time. So the first time the loop runs the following type of code:

tiffcp.exe file1.tif results.tif

The result is a perfect 476k tif file. But the next iteration of the loop needs to merge the second file plus the contents of the first "results" tif file. So I do this:

tiffcp.exe results.tif file2.tiff results.tif

The results each time are a blank 1K tiff file?

All the examples I can find of tiffcp.exe say file1.tif file2.tif results.tif, none use the results file to write back to itself?

Any suggestions on how to do this?

A: 

I believe your problem is caused by the use of results.tif as both input as output. If you increment the file name (i.e. results1.tif to results2.tif etc.) I believe it should work.

This is a rather inefficient approach (tiff1 is copied 9 times if you have 10 files). Since you refer to libtiff, you may take a look at the source of libtiff cp and check if it is worthwhile to embed it.

Adriaan
Yes, this is defintely not the smallest, quickest or efficient way of handling the processing. There is a lot of cleanup work that goes with this way to manage the disk space as well. This is a ASP.NET app. How would I embed libtiff in this project?
WildBill
Libtiff.net (see Brobrovsky's comment) is an very good choice. It's source is C#, but you may also use binaries provided. Also, you could use it to directly brew your own tiff if the image writing is under your control. Should be fairly straightforward.
Adriaan
+1  A: 

For an ASP.NET project you may want to try LibTiff.Net (free, open source, BSD license). That port of libtiff library contains tiffcp utility with source code. You may try to use it in your code.

Bobrovsky