Check how many pages are included in a multi-page image file with GraphicsMagick

StackOverflow https://stackoverflow.com/questions/22333814

  •  13-06-2023
  •  | 
  •  

Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top