in reply to Getting Imager to work with Activeperl

If you're only interested in is counting the pages in TIFF files, you don't need Imager. Check out this node for a pure Perl solution. The program counts the pages per TIFF file, so all you would need is a slight modification to totalize the count from all files.
  • Comment on Re: Getting Imager to work with Activeperl

Replies are listed 'Best First'.
Re^2: Getting Imager to work with Activeperl
by NewRun (Novice) on Oct 28, 2009 at 01:52 UTC
    While I don't understand everything that this code does, it has worked wonderfully. Thank you.

      You're welcome. The code was ripped out of a fax file manager project I wrote a while back. It doesn't make much sense without reading a copy of the TIFF specification, but in a nutshell the code traverses a chain of image directories (basically a linked list) using the while loop. Each image directory contains meta data and pointers for one image, so counting the directories gives you the number of images in the file. Each directory is also parsed for the pointer to the next image directory in the chain. Since TIFF files can be big or little endian, this is detected after the first read so the binary data can be properly unpacked.

      Note that the count too high detection is to prevent the possibility of a corrupt file causing an endless loop. It was arbitrarily set to 100, but a TIFF file can have any number of images, so set it to something sensible for your application.