Question

Is there a way to determine in advance how many pages are included in a multi page tif image with GraphicsMagick ? I know I can select the first page in this way : image.tif[0], and probably iterating the array until the command fail will return the last image, but I don't think this is the best approach.

Was it helpful?

Solution

You can get a numbered list of the pages with

gm identify image.tif

and look at the last line, or count the lines. The images are numbered 0 thru N -1.

OTHER TIPS

It is not too late to answer.

I think it is not possible to get the page count beforehand, not even with libtiff. However, you can avoid the trial and error by using Magick::readImages:

// Magick++
std::vector<Magic::Image> images;
Magick::readImages(&images, "multipage.tif");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top