Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|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
2  
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

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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