Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
I found the documentation for the strings in the format option (available at %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

Shorter than all of the others:

identify multipage.tif | wc -l
share|improve this answer

identify multipage.tif | wc -l

(-format "%p" or %n produced bogus results for me)

share|improve this answer

Combined from the answers supplied (using -format and wc to count):

identify -format "%p " multipage.tif | wc -w

And just to mention ... it's the page numbers we get ( 1 for 1 page, 1 2 for 2 pages, 1 2 3 for 3 pages and 1 2 3 ... 19 20 21 22 for 22 pages)

share|improve this answer

Your Answer


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.