ImageMagick: how to batch combine multiple TIFF fi

2020-04-10 02:18发布

I have 600 TIFF files in a directory, c:\temp.

The file names are like:

001_1.tif,
001_2.tif,
001_3.tif

002_1.tif,
002_2.tif,
002_3.tif
....
....
200_1.tif,
200_2.tif,
200_3.tif

The combined files should be placed in same directory and the files should be named like:

1_merged.tif
2_merged.tif
.....
.....
200_merged.tif

I am looking for any single command-line /batch-file to do so through ImageMagick convert/ mogrify command or any other command/tools.

Please note the overall time taken should not be more than 5 second.

2条回答
男人必须洒脱
2楼-- · 2020-04-10 02:51

Assuming you want to combine the 600 single-page TIFFs into one single multi-page TIFF (per set of 3), it is as simple as:

 convert  001_*.tiff  1_merged.tiff
 convert  002_*.tiff  2_merged.tiff
 [....]
 convert  200_*.tiff  200_merged.tiff

Please note that nobody will be able to guarantee any timing/performance benchmarks... least while we don't even have any idea how exactly your input TIFFs are constituted. (Are they 10000x10000 pixels or are they 20x20 pixels?, Are they color or grayscale?, etc.pp.)

This is different from Mark's answer, because he seems to have assumed you want to combine the input files all into a 1-page image, where the originals are tiled across a larger page...

查看更多
混吃等死
3楼-- · 2020-04-10 02:55

This should do it - I will leave you to do error checking in case you haven't actually got all the images you suggest!

@ECHO OFF
setlocal EnableDelayedExpansion
FOR /L %%A IN (1,1,200) DO (
   set "formattedValue=000000%%A"
   set "x=!formattedValue:~-3!"
   convert !x!_*.tif +append !x!_merged.tif
   echo !x!
)

So, if your images look like this

001_1.tif

enter image description here

001_2.tif

enter image description here

001_3.tif

enter image description here

you will get this in merged_001.tif

enter image description here

If you change +append to -append then merged_001.tif will be like this:

enter image description here

If you remove +append altogether, you will get 200 multi-page TIFs with 3 pages each - same as Kurt's answer.

查看更多
登录 后发表回答