perldoc > Image::Info

๐Ÿ“› Image::Info - Extract meta information from image files

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Get all image infomy $info = image_info("file.jpg");Returns a hash with dimensions, type, MIME, etc.
Get only the file typemy $type = image_type("file.jpg");Fasterโ€”returns a hash with file_type key
Get width and heightmy($w, $h) = dim($info);Expects hash from image_info()
HTML-dimensions stringhtml_dim($info)Returns WIDTH="..." HEIGHT="..." for HTML tags
Handle errorsif (my $error = $info->{error}) { die $error; }Check the error key on failure
Examine color type$info->{color_type}e.g., "RGB", "Gray", "Indexed-RGB"
Get MIME type$info->{file_media_type}e.g., "image/jpeg", "image/png"
Get suggested file extension$info->{file_ext}e.g., "jpg", "png"

๐Ÿ“„ 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

This module provides functions to extract various kinds of meta information from image files.

๐Ÿ“ค EXPORTS

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

๐Ÿ”ง METHODS

The following functions are provided by the Image::Info module:

๐Ÿ“ธ image_info( $file )

๐Ÿ“ธ image_info( \$imgdata )

๐Ÿ“ธ image_info( $file, key => value,... )

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 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( $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.

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( $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 directly into HTML or SVG <img>-tags. E.g.:

print "<img src="..." @{[html_dim($info)]}>\n";

โš™๏ธ 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".

๐Ÿ–ผ๏ธ 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:

๐Ÿ“ Supported Image Formats

The following image file formats are supported:

โš ๏ธ 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.

๐Ÿ“š SEE ALSO

Image::Size, Image::ExifTool

๐Ÿ‘ฅ AUTHORS

Copyright 1999-2004 Gisle Aas.

See the CREDITS file 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.

Image::Info
๐Ÿ“› Image::Info - Extract meta information from image files ๐Ÿš€ Quick Reference ๐Ÿ“„ SYNOPSIS ๐Ÿ“– DESCRIPTION
๐Ÿ“ค EXPORTS ๐Ÿ”ง METHODS ๐Ÿ“ธ image_info( $file ) ๐Ÿ“ธ image_info( \$imgdata ) ๐Ÿ“ธ image_info( $file, key => value,... ) ๐Ÿ” image_type( $file ) ๐Ÿ” image_type( \$imgdata ) ๐Ÿ“ dim( $info_hash ) ๐Ÿ“ html_dim( $info_hash ) โš™๏ธ determine_file_format( $filedata )
๐Ÿ–ผ๏ธ Image descriptions ๐Ÿ“ Supported Image Formats โš ๏ธ CAVEATS ๐Ÿ“š SEE ALSO ๐Ÿ‘ฅ AUTHORS โš–๏ธ LICENSE

Generated by phpman v4.9.25-25-g40dbf62 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-15 13:55 @216.73.216.85
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^