2004.08.24 08:43 "[Tiff] Insetring text", by Ionita Alexandru

2004.08.24 17:50 "Re: [Tiff] Insetring text", by Joris Van Damme

How can I access all pages of a multi-page tiff using imageMagick or graphicsMagick

I don't know about those packages...

to append to all of this, page numers, and how can I find out the number of pages in a multi-page tiff?

...but on the TIFF level, there is no way to know the number of pages, other then counting them. That is because each page only 'knows' about the location of the next one. May seem braindead, but it's actually a very convinient structure.

Counting them can be done with following code. (I'm not a C coder, but this is from the FM, start to R here: http://www.remotesensing.org/libtiff/libtiff.html.)

TIFF* tif = TIFFOpen('yada.tiff', "r");
if (tif) {
    int dircount = 0;
    do {
    } while (TIFFReadDirectory(tif));
    /* dircount is your number of pages */

There is a function in tif_dir...

TIFFNumberOfDirectories(TIFF* tif)

...that seems to do the same, only it should be faster since it doesn't bother to read complete tagsets, and TIFFReadDirectory does (and may even decompress a jpeg strip and all, from what I've read in Bugzilla, but I may be wrong).

Oh, there's a page number tag...

I must annotate this files with page numbers in format 1/n, 2/n, 3/n.... n/n, where n is the total number of pages.

...that is two shorts, and has exactly this format (except that page numbers should start with 0). See http://www.awaresystems.be/imaging/tiff/tifftags/pagenumber.html. I wouldn't depend on it for reading purposes. (Because all sorts of things could have happend to it. It may have been correct in a file at first. Next, an application may have concattenated TIFF files, and left the PageNumber tag unchanged. Next, another tool could have unlinked some IFD's, or swapped some, or whatever. And also, it's not written most of the time to begin with.) But it might be suitable for your 'annotating' purposes.

Joris Van Damme
Download your free TIFF tag viewer for windows here: