0

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.

Cris69
  • 520
  • 1
  • 14
  • 40

2 Answers2

1

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.

Glenn Randers-Pehrson
  • 11,940
  • 3
  • 37
  • 61
0

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");
josuegomes
  • 451
  • 4
  • 15