How can I get a page count of a multi-page .tif image.
I browsed in CPAN, but I can't find the TIFF.pm.
Image::TIFF is part of the Image-Info package. If you install the
package, you'll have it. You can't, or at least shouldn't, ever try to
get separate files out of a distribution.
However, I don't think that that supports multi-image formats (I might
be wrong. I haven't actually tried it, just browsed the documentation).
Is there any way to get the page count in perl?
Image::Magick will be able to tell you this. You open the image as an
IM object, and then you just count the number of elements in it.
If not, what is the easiest way to do it using C, etc.?
Probably also with the ImageMagick libary, or maybe directly with the
freely available tiff library (
www.libtiff.org), possibly already on
your system, depending on your OS and vendor.
Could someone give me the easiest steps to do it as I am quite
new to perl and programming?
Lessee..
#!/opt/perl/bin/perl
use strict;
use warnings;
use Image::Magick;
# Create a multi-image TIFF document
{
my $im = Image::Magick->new();
# Read some JPG images
my $rc = $im->Read(glob("/tmp/P*.JPG"));
die $rc if $rc;
# Save the whole thing as a TIFF file
$rc = $im->Write("foo.tiff");
die $rc if $rc;
}
# Read the TIFF document
{
my $im = Image::Magick->new();
my $rc = $im->Read("foo.tiff");
die $rc if $rc;
# An Image::Magick object is just a reference to an array, with
# each element an image.
my $n_images = @$im;
print "I've got $n_images images\n";
}
Note that Image::Magick generally relies on an external tiff library
to write and read images.
Just a side question:
Is tiff the only format that supports multi-page images,
or are there any other and if any, what are those?
Photoshop, MNG, ImageMagick's MIFF format, GIMP XCF, GIF, PostScript,
PDF, FAX, FITS (I believe), The various Flash and Macromedia formats,
MPEG, and many others. Not all of these are pure image formats or even
mainly image formats, and what a "frame/page/image/layer" in each of
these means is often application dependent. In fact, what multiple
images in a single TIFF document mean is dependent on the encoding and
context.
Martien