# perldoc > Image::Info

---
type: CommandReference
command: Image::Info
mode: perldoc
section: 
source: perldoc
---

## Quick Reference
- `image_info("file.jpg")` — get all image metadata as a hash reference
- `image_info($fh)` — process an open file handle
- `image_type("file.jpg")` — fast detection of file type (reads only 11 bytes)
- `dim($info)` — return width and height from an info hash
- `html_dim($info)` — return dimensions as `width="X" height="Y"` string for HTML/SVG
- `determine_file_format($data)` — deduce format from raw first bytes (e.g., "JPEG", "PNG")

## Name
Extract meta information from image files

## Synopsis
perl
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);
## Functions
- `image_info($file | $fh | \$data, %options)` — returns one or more hash references describing the image(s). Accepts a filename, file handle, or a scalar reference containing raw image data. In list context returns all images; in scalar context only the first. On error the hash contains the key `error`.
- `image_type($file | $fh)` — returns a hash with only `file_type` (e.g., 'GIF', 'JPEG'). Much faster than `image_info()` because it reads only the first 11 bytes and does not load format-specific drivers. On error sets `error` and `Errno`.
- `dim($info)` — given an info hash from `image_info()`, returns the image dimensions `($width, $height)`. In scalar context returns a string.
- `html_dim($info)` — returns the dimensions as a string suitable for HTML `<img>` attributes: `width="W" height="H"`.
- `determine_file_format($data)` — takes a Perl scalar containing the first bytes of a file and returns a string like "BMP", "JPEG", or `undef` if unknown.

## Image Metadata Keys
The hash returned by `image_info()` contains the following keys. Lowercase keys are always present (unless an error occurs); mixed-case keys appear only when the information is available.

- `file_media_type` — MIME type, e.g., `"image/png"`, `"image/jpeg"`
- `file_ext` — suggested file extension, e.g., `"png"`, `"jpg"`
- `width` — horizontal pixels
- `height` — vertical pixels
- `color_type` — `"Gray"`, `"GrayA"`, `"RGB"`, `"RGBA"`, `"CMYK"`, `"YCbCr"`, `"CIELab"`; may be prefixed with `"Indexed-"` for palette‑based images
- `resolution` — physical size or pixel aspect ratio, e.g., `"72 dpi"`, `"300/300 dpi"`
- `SamplesPerPixel` — number of channels
- `BitsPerSample` — array reference of bits per channel
- `Comment` — textual comments (array reference if multiple)
- `Interlace` — interlace method if interlaced
- `Compression` — compression algorithm used
- `Gamma` — a number
- `LastModificationTime` — ISO date string

## Supported Image Formats
- **BMP** — Microsoft Device Independent Bitmap (DIB, RLE)  
  See [Image::Info::BMP](https://metacpan.org/pod/Image::Info::BMP)
- **GIF** — GIF87a and GIF89a; `GIF_Version` key, Netscape loop extension (`GIF_Loop` = `"forever"` or count). Multiple images returned in list context.
- **ICO** — Microsoft Windows Icon Resource format
- **JPEG** — extracts JFIF and Exif data (timestamp, camera model, focal length, GPS, etc.). `color_type` may be `"Gray"`, `"YCbCr"`, `"CMYK"`.  
  Exif spec: [http://www.exif.org/specifications.html](http://www.exif.org/specifications.html)
- **PNG** — reads IHDR, PLTE, gAMA, pHYs, tEXt, tIME chunks; `PNG_Chunks` key lists chunk sequence
- **PBM/PGM/PPM** — all available information extracted
- **SVG** — provides attributes and metadata of the vector graphic
- **TIFF** — Adobe TIFF and Exif tags  
  Spec: [http://partners.adobe.com/public/developer/tiff/](http://partners.adobe.com/public/developer/tiff/)
- **WBMP** — no magic number; cannot be used with the normal functions. See [Image::Info::WBMP](https://metacpan.org/pod/Image::Info::WBMP)
- **WEBP** — supports VP8 (lossy), VP8L (lossless), VP8X (extended). Sets `Animation` if animated, otherwise `Compression` = `"VP8"` or `"Lossless"`.
- **XBM** — see [Image::Info::XBM](https://metacpan.org/pod/Image::Info::XBM)
- **XPM** — see [Image::Info::XPM](https://metacpan.org/pod/Image::Info::XPM)

## Caveats
This module is suitable for basic image information (type, dimensions, color depth). For full, up‑to‑date EXIF parsing, use [Image::ExifTool](https://metacpan.org/pod/Image::ExifTool).

## See Also
- [Image::Size](https://metacpan.org/pod/Image::Size)
- [Image::ExifTool](https://metacpan.org/pod/Image::ExifTool)