Image::Info(3)
π NAME π
This is the Image::Info(3) page from the User Contributed Perl Documentation, and it's all about 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 $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 πΈ
Okay so this module is literally a little toolbox for pulling all kinds of meta information out of image files. Main character energy for image metadata. π
π EXPORTS π
It exports nothing by default, but bestie, you can ask for these methods and it will hand them over:
image_info
image_type
dim
html_dim
determine_file_type
π§ METHODS π§
The following functions are provided by the Image::Info module:
π«Ά image_info π«Ά
image_info( $file )image_info( \$imgdata )image_info( $file, key => value,... )
This one takes the name of a file or a file handle as its argument, and it returns one or more hashes β actually hash references, no cap β 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. Efficient? Obsessed. β¨
In case of error, a 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 an 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.
π¦ image_type π¦
image_type( $file )image_type( \$imgdata )
Returns a hash with only one key, file_type. The value will be the type of the file. On error, sets the two keys error and Errno.
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. First 11 bytes and done? That's the speedrun. πββοΈπ¨
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 HASH reference, with the $type->{error} key set if there was an error.
On success, the HASH 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 ('GIF', 'JPEG', 'TIFF' 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.
π
dim π
dim( $info_hash )
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. Width and height, cute and concise. π
π html_dim π
html_dim( $info_hash )
Returns the dimensions as a string suitable for embedding directly into HTML or SVG <img>-tags. E.g.:
print "<img src="..." @{[html_dim($info)]}>\n";
π₯ determine_file_format π₯
determine_file_format( $filedata )
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 "BMP" or "JPEG". Format detective mode: activated. π΅οΈββοΈ
πΌοΈ 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 occurred (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β This is the suggested file name extension 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 uses the nameImageLengthfor 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 inspired 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 "dpi", "dpm" or "dpcm" (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 thecolor_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 asSamplesPerPixel.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 tells which interlace method is used.Compressionβ This tells you which compression algorithm is used.Gammaβ A number.LastModificationTimeβ An ISO date string.
π Supported Image Formats π
The following image file formats are supported:
- AVIF β Supports the basic standard info key names.
- BMP β This module supports the Microsoft Device Independent Bitmap format (BMP, DIB, RLE).
- For more information see
Image::Info::BMP.
- For more information see
- GIF β Both
GIF87aandGIF89aare supported and the version number is found asGIF_Versionfor 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 extension to loop animation sequences is represented by the
GIF_Loopkey for the first image. - The value is either
"forever"or a number indicating loop count.
- GIF files can contain multiple images, and information for all images will be returned if
- ICO β This module supports the Microsoft Windows Icon Resource format (
.ico). - JPEG β For JPEG files we extract information both from
"JFIF"and"Exif"application chunks."Exif"is the file format written by most digital cameras. It encodes things like timestamp, camera model, focal length, exposure time, aperture, flash usage, GPS position, etc.- The
"Exif"spec can be found at:<http://www.exif.org/specifications.html>. - The
color_typeelement may have the following values:"Gray","YCbCr", and"CMYK". Note that detecting"RGB"and"YCCK"currently does not work, but will hopefully in future.
- PNG β Information from IHDR, PLTE, gAMA, pHYs, tEXt, tIME chunks are extracted. The sequence of chunks are also given by the
PNG_Chunkskey. - PBM/PGM/PPM β All information available is extracted.
- SVG β Provides a plethora of attributes and metadata of an SVG vector graphic.
- TIFF β The
TIFFspec can be found at:<http://partners.adobe.com/public/developer/tiff/>.- The EXIF spec can be found at:
<http://www.exif.org/specifications.html>.
- The EXIF spec can be found at:
- WBMP β wbmp files have no magic, so cannot be used with the normal Image::Info functions. See
Image::Info::WBMPfor more information. - WEBP β VP8 (lossy), VP8L (lossless) and VP8X (extended) files are supported. Sets the key
Animationto true if the file is an animation. Otherwise sets the keyCompressionto eitherVP8orLossless. - XBM β See
Image::Info::XBMfor details. - XPM β See
Image::Info::XPMfor details.
π CAVEATS π
While this module is fine for parsing basic image information like image type, dimensions and color depth, it is probably not good enough for parsing out more advanced information like EXIF data. If you want an up-to-date and tested EXIF parsing library, please use Image::ExifTool. Real talk: use the right tool for the EXIF job, bestie. π«Ά
π SEE ALSO π
Image::Size, Image::ExifTool
π AUTHORS π
- Copyright 1999-2004 Gisle Aas.
- See the
CREDITSfile for a list of contributors and authors. - Tels - (c) 2006 - 2008.
- Current maintainer: Slaven Rezic - (c) 2008 - 2015.
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl v5.8.8 itself. Free software, iconic behavior. π±
π
that's the whole page, bestie β perl v5.42.0, dated 2024-03-08, Image::Info(3) out. π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-Image-Info 1.440.0-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms