SYNOPSIS

 use Image::Info qw(image_info dim);

 my $info = image_info("image.jpg");
 if (my $error = $info->{error}) {
     die "Can't parse image info: $error\n";
 }
 my $color = $info->{color_type};

 my $type = image_type("image.jpg");
 if (my $error = $type->{error}) {
     die "Can't determine file type: $error\n";
 }
 die "No gif files allowed!" if $type->{file_type} eq 'GIF';

 my($w, $h) = dim($info);

DESCRIPTION

Please note that this module is deprecated and should not be used. Alternatively, try one of the following modules:

Image::Size, Image::ExifTool.

The code in this module is old, unreviewed, hackish, still has numerous bugs and is incomplete in quite a few cases.

While this module is sort-of maintained (e.g. the most critical security-related bugs are fixed), no new features will be added and numerous minor bugs are very likely sprinkled through the entire code base. You have been warned.

This module provide functions to extract various kind of meta information from image files.

\$1

Exports nothing by default, but can export the following methods on request:

image_info image_type dim html_dim determine_file_type The following functions are provided by the \*(C`Image::Info\*(C' module:

image_info( \$imgdata )

This function takes the name of a file or a file handle as argument and will return one or more hashes (actually hash references) describing the images inside the file. If there is only one image in the file only one hash is returned. In scalar context, only the hash for the first image is returned. In case of error, a hash containing the \*(L"error\*(R" key will be returned. The corresponding value will be an appropriate error message. If a reference to a scalar is passed as argument to this function, then it is assumed that this scalar contains the raw image data directly. The image_info() function also take optional key/value style arguments that can influence what information is returned. See Image::Info::XPM and other Image::Info submodules for the parameters that they take.

image_type( \$imgdata )

Returns a hash with only one key, \*(C`file_type\*(C'. The value will be the type of the file. On error, sets the two keys \*(C`error\*(C' and \*(C`Errno\*(C'. This function is a dramatically faster alternative to the image_info function for situations in which you only need to find the image type. It uses only the internal file-type detection to do this, and thus does not need to load any of the image type-specific driver modules, and does not access to entire file. It also only needs access to the first 11 bytes of the file. To maintain some level of compatibility with image_info, image_type returns in the same format, with the same error message style. That is, it returns a \s-1HASH\s0 reference, with the \*(C`$type->{error}\*(C' key set if there was an error. On success, the \s-1HASH\s0 reference will contain the single key 'file_type', which represents the type of the file, expressed as the type code used for the various drivers ('\s-1GIF\s0', '\s-1JPEG\s0', '\s-1TIFF\s0' and so on). If there are multiple images within the file they will be ignored, as this function provides only the type of the overall file, not of the various images within it. This function will not return multiple hashes if the file contains multiple images. Of course, in all (or at least effectively all) cases the type of the images inside the file is going to be the same as that of the file itself. Takes a hash as returned from image_info() and returns the dimensions ($width, $height) of the image. In scalar context returns the dimensions as a string. Returns the dimensions as a string suitable for embedding directly into \s-1HTML\s0 or \s-1SVG\s0 <img>-tags. E.g.: print "<img src="..." @{[html_dim($info)]}>\n"; Determines the file format from the passed file data (a normal Perl scalar containing the first bytes of the file), and returns either undef for an unknown file format, or a string describing the format, like \*(L"\s-1BMP\s0\*(R" or \*(L"\s-1JPEG\s0\*(R".

Image descriptions

The image_info() function returns meta information about each image in the form of a reference to a hash. The hash keys used are in most cases based on the \s-1TIFF\s0 element names. All lower case keys are mandatory for all file formats and will always be there unless an error occured (in which case the \*(L"error\*(R" key will be present.) Mixed case keys will only be present when the corresponding information element is available in the image.

The following key names are common for any image format:

file_media_type

This is the \s-1MIME\s0 type that is appropriate for the given file format. The corresponding value is a string like: \*(L"image/png\*(R" or \*(L"image/jpeg\*(R".

file_ext

The is the suggested file name extention for a file of the given file format. The value is a 3 letter, lowercase string like \*(L"png\*(R", \*(L"jpg\*(R".

width

This is the number of pixels horizontally in the image.

height

This is the number of pixels vertically in the image. (\s-1TIFF\s0 use the name ImageLength for this field.)

color_type

The value is a short string describing what kind of values the pixels encode. The value can be one of the following: Gray GrayA RGB RGBA CMYK YCbCr CIELab These names can also be prefixed by \*(L"Indexed-\*(R" if the image is composed of indexes into a palette. Of these, only \*(L"Indexed-RGB\*(R" is likely to occur. It is similar to the \s-1TIFF\s0 field PhotometricInterpretation, but this name was found to be too long, so we used the \s-1PNG\s0 inpired term instead.

resolution

The value of this field normally gives the physical size of the image on screen or paper. When the unit specifier is missing then this field denotes the squareness of pixels in the image. The syntax of this field is: <res> <unit> <xres> "/" <yres> <unit> <xres> "/" <yres> The <res>, <xres> and <yres> fields are numbers. The <unit> is a string like \*(C`dpi\*(C', \*(C`dpm\*(C' or \*(C`dpcm\*(C' (denoting "dots per inch/cm/meter).

SamplesPerPixel

This says how many channels there are in the image. For some image formats this number might be higher than the number implied from the \*(C`color_type\*(C'.

BitsPerSample

This says how many bits are used to encode each of samples. The value is a reference to an array containing numbers. The number of elements in the array should be the same as \*(C`SamplesPerPixel\*(C'.

Comment

Textual comments found in the file. The value is a reference to an array if there are multiple comments found.

Interlace

If the image is interlaced, then this tell which interlace method is used.

Compression

This tells you which compression algorithm is used.

Gamma

A number.

LastModificationTime

A \s-1ISO\s0 date string

Supported Image Formats

The following image file formats are supported:

\s-1BMP\s0

This module supports the Microsoft Device Independent Bitmap format (\s-1BMP\s0, \s-1DIB\s0, \s-1RLE\s0). For more information see Image::Info::BMP.

\s-1GIF\s0

Both GIF87a and GIF89a are supported and the version number is found as \*(C`GIF_Version\*(C' for the first image. \s-1GIF\s0 files can contain multiple images, and information for all images will be returned if image_info() is called in list context. The Netscape-2.0 extention to loop animation sequences is represented by the \*(C`GIF_Loop\*(C' key for the first image. The value is either \*(L"forever\*(R" or a number indicating loop count.

\s-1JPEG\s0

For \s-1JPEG\s0 files we extract information both from \*(C`JFIF\*(C' and \*(C`Exif\*(C' application chunks. \*(C`Exif\*(C' is the file format written by most digital cameras. This encode things like timestamp, camera model, focal length, exposure time, aperture, flash usage, \s-1GPS\s0 position, etc. The following web page contain description of the fields that can be present: http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html The \*(C`Exif\*(C' spec can be found at: http://www.exif.org/specifications.html

\s-1PNG\s0

Information from \s-1IHDR\s0, \s-1PLTE\s0, gAMA, pHYs, tEXt, tIME chunks are extracted. The sequence of chunks are also given by the \*(C`PNG_Chunks\*(C' key.

\s-1PBM/PGM/PPM\s0

All information available is extracted.

\s-1SVG\s0

Provides a plethora of attributes and metadata of an \s-1SVG\s0 vector grafic.

\s-1TIFF\s0

The \*(C`TIFF\*(C' spec can be found at: <http://partners.adobe.com/public/developer/tiff/> The \s-1EXIF\s0 spec can be found at: <http://www.exif.org/>

\s-1XBM\s0

See Image::Info::XBM for details.

\s-1XPM\s0

See Image::Info::XPM for details.

CAVEATS

Note that while the module is still maintained, no new features will be added and numerous bugs remain throughout the code base.

Especially the \s-1EXIF\s0 parsing code is buggy, not tested at all, and quite incomplete (a lot of manufacturer's MakerNotes and tags are not parsed at all). If you want a stable, feature-complete, up-to-date and tested \s-1EXIF\s0 parsing library, please use Image::ExifTool.

Likewise, the image parsing code is quite hackish and seems to contain an endless supply of bugs that crash, or hang with malformed input.

RELATED TO Image::Info…

Image::Size, Image::ExifTool

AUTHORS

Copyright 1999-2004 Gisle Aas.

See the \s-1CREDITS\s0 file for a list of contributors and authors.

Now maintained by Tels - (c) 2006 - 2008.

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl v5.8.8 itself.