man Image::Info () - Extract meta information from image files
NAME
Image::Info - Extract meta information from image files
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($w, $h) = dim($info);
DESCRIPTION
This module provide functions to extract various kind of meta information from image files. The following functions are provided by the CWImage::Info 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, and hash containing the error 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.
Takes an hash as returned from image_info() and returns the dimensions
($width, CW$height) of the image. In scalar context returns the
dimensions as a string.
Returns the dimensions as a string suitable for embedding directly
into HTML <img>-tags. E.g.:
print "<img src="..." @{[html_dim($info)]}>\n";
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 TIFF 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 error 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 MIME type that is appropriate for the given file format. The corresponding value is a string like: image/png or image/jpeg.
- 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 png, jpg.
- width
- This is the number of pixels horizontally in the image.
- height
- This is the number of pixels vertically in the image. (TIFF 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 Indexed- if the image is composed of indexes into a palette. Of these, only Indexed-RGB is likely to occur. (It is similar to the TIFF field PhotometricInterpretation, but this name was found to be too long, so we used the PNG 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 CWdpi, CWdpm or CWdpcm (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 CWcolor_type.
- 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 CWSamplesPerPixel.
- 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 tell which compression algorithm is used.
- Gamma
- A number.
- LastModificationTime
- A ISO date string
Supported Image Formats
The following image file formats are currently supported:
- BMP
- This module supports the Microsoft Device Independent Bitmap format (BMP, DIB, RLE). For more information see Image::Info::BMP.
- GIF
- Both GIF87a and GIF89a are supported and the version number is found as CWGIF_Version for the first image. GIF 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 CWGIF_Loop key for the first image. The value is either forever or a number indicating loop count.
- JPEG
-
For JPEG files we extract information both from CWJFIF and CWExif
application chunks.
CWExif is the file format written by most digital cameras. This
encode things like timestamp, camera model, focal length, exposure
time, aperture, flash usage, GPS position, etc. The following web
page contain description of the fields that can be present:
http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
The CWExif spec can be found at:http://exif.org/specifications.html
- PNG
- Information from IHDR, PLTE, gAMA, pHYs, tEXt, tIME chunks are extracted. The sequence of chunks are also given by the CWPNG_Chunks key.
- PBM/PGM/PPM
- All information available is extracted.
- SVG
- SVG also provides (for) a plethora of attributes and metadata of an image. See Image::Info::SVG for details.
- TIFF
- The CWTIFF spec can be found at: http://partners.adobe.com/asn/developer/PDFS/TN/TIFF6.pdf Also good writeup on exif spec at: http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
- XBM
- See Image::Info::XBM for details.
- XPM
- See Image::Info::XPM for details.
SEE ALSO
Image::Size
AUTHORS
Copyright 1999-2004 Gisle Aas.
GIF fixes by Ralf Steines <metamonk@yahoo.com>.
ASCII, BMP SVG, XPM and XBM support added by Jerrad Pierce <belg4mit@mit.edu>/<webmaster@pthbb.org>.
Exif MakerNote decoding by Jay Soffian <jay@loudcloud.com>.
TIFF support by <clarsen@emf.net>.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.