How to get the number of pages from a TIF?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Antoine4851
Posts: 6
Joined: 2015-07-21T02:45:54-07:00
Authentication code: 1151

How to get the number of pages from a TIF?

Post by Antoine4851 »

Hi,

I want to get the number of pages from a TIF using command line.
I know there's the component identify.exe but I don't find the parameters to apply.
I need to get the number of pages into a variable.

Thanks for any help

Antoine
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get the number of pages from a TIF?

Post by snibgo »

One method:

Code: Select all

identify -ping -format %n\n multi.tiff
This will output (n) lines, one per image. Each line will contain the number (n). Grab any of those into a variable. See http://www.imagemagick.org/script/escape.php

There may be a single-line solution, but I can't find one.
snibgo's IM pages: im.snibgo.com
Antoine4851
Posts: 6
Joined: 2015-07-21T02:45:54-07:00
Authentication code: 1151

Re: How to get the number of pages from a TIF?

Post by Antoine4851 »

I tried this method but I don't know how to put the result in a variable...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to get the number of pages from a TIF?

Post by snibgo »

ImageMagick won't put it into a variable. Your script needs to do that.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to get the number of pages from a TIF?

Post by fmw42 »

What platform and what version of IM. If Unix, then

Code: Select all

number=$(identify -ping -format "%n\n" multi.tiff | tail -n -1)
Post Reply