NAME
Image::Info - Extract information from image files
NOTE
This is an alpha release of the Image::Info
module. The interface to the routines described below is likely to change.
SYNOPSIS
use Image::Info qw(image_info dim);
my $info = image_info("image.jpg");
my($w, $h) = dim($info);
DESCRIPTION
This module provide functions to extract various information from image files. The following functions are provided:
- image_info( $file )
-
This function takes the name of a file or a file handle as argument and will return one or more hashes 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.
- dim( $info_hash )
-
Takes an hash as returned from image_info() and returns the dimensions ($width, $height) of the image. In scalar context returns the dimensions as a string.
- html_dim( $info_hash )
-
Returns the dimensions as a string suitable for embedding into HTML tags like <img src="...">.
Image descriptions
The image_info() function return information about an image as a hash. The key values that can occur is based on the TIFF names.
The following names are common for any image format:
- FileMediaType
-
This is the MIME type that is appropriate for the given file format. This is a string like: "image/png" or "image/jpeg".
- FileExt
-
The is the suggested file name extention for a file of the given file format. It is a 3 letter, lowercase string like "png", "jpg".
- ImageWidth
-
This is the number of pixels horizontally in the image.
- ImageHeight
-
This is the number of pixels vertically in the image. (TIFF use the name ImageLength for this field.)
- ColorType
-
This 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 to long, so we used the PNG term instead :-)
- 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
ColorType
. - BitsPerSample
-
This says how many bits are used to encode each of samples. The number of numbers here should be the same as
SamplesPerPixel
. - Resolution
-
This field is instead of XResolution/YResolution when the pixels in the image are square.
- ResolutionUnit
-
This is a string like
dpi
,dpm
,dpcm
giving the physical size of the image on screen or paper. If missing when XResolution/YResolution is present, then the resolution is used to denote the squareness of pixels in the image. - XResolution
-
The horizontal size of pixels.
- YResolution
-
The vertical size of pixels.
- Comment
-
Textual comments found in the file.
- Interlace
-
If the image is interlaced, then this tell which interlace method is used.
- Compression
-
This tell which compression algorithm is used.
Supported Image Formats
The following image file formats are supported:
- JPEG
-
For JPEG files we extract information both from
JFIF
andExif
application chunks.Exif
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. - PNG
-
Information from IHDR, PLTE, gAMA, pHYs, tEXt, tIME chunks are extracted. The sequence of chunks are also given by the
PNG_Chunks
key. - GIF
-
Both GIF87a and GIF89a are supported and the version number is found as
GIF_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 theGIF_Loop
key for the first image. The value is either "forever" or a number indicating loop count.
SEE ALSO
AUTHOR
Copyright 1999 Gisle Aas.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.