Is there a way to get the number of tiffs in a multi-tiff with a command line utility in ImageMagick?

What I want to to is to extract (split) the multi-tiff into single files. However if the tiff only contains one tiff (is not a multi-tiff), I would like to do nothing at all... Also if I use the "%d"-option to name the output files I get the "%d" in the file name if it is only one.

...or is there another way to use ImageMagick to avoid strange filenames when converting?

link|improve this question

80% accept rate
feedback

2 Answers

up vote 2 down vote accepted

You can return the number of pages in a tiff using identify -format "%p" multipage.tif.

link|improve this answer
Interesting! Tried it and got back: 12345678910111213141516171819202122 if my tiff holds 22 images. Not quite what i expected but will investigate more... – Anders Apr 15 '10 at 7:06
Hmmm..... I don't have a multipage tiff to try it on. What version of IM are you using? On what OS? – DaveParillo Apr 15 '10 at 16:32
I have tried 32-bit IM version 6.6.1-2 Q8 and Q16 on Windows XP 32-bit and Windows 7 64-bit. I have also tried 64-bit IM 6.6.1-2 on Windows 7 64-bit. All generate the same output with the command you suggested. – Anders Apr 16 '10 at 6:43
I found the documentation for the strings in the format option (available at imagemagick.org). %p displays pages and %n displays the number of scenes, which is what I was looking for. The command I will use is then: identify -format "%n" multipage.tif . – Anders Apr 16 '10 at 6:56
feedback

You can use the following to count the number of pages in a TIFF file:

tiffinfo output_file_name.tif | grep "Page Number" | grep -c "P"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.