{
    "mode": "perldoc",
    "parameter": "Image::Info",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Image%3A%3AInfo/json",
    "generated": "2026-06-15T14:20:32Z",
    "synopsis": "use Image::Info qw(imageinfo dim);\nmy $info = imageinfo(\"image.jpg\");\nif (my $error = $info->{error}) {\ndie \"Can't parse image info: $error\\n\";\n}\nmy $color = $info->{colortype};\nmy $type = imagetype(\"image.jpg\");\nif (my $error = $type->{error}) {\ndie \"Can't determine file type: $error\\n\";\n}\ndie \"No gif files allowed!\" if $type->{filetype} eq 'GIF';\nmy($w, $h) = dim($info);",
    "sections": {
        "NAME": {
            "content": "Image::Info - Extract meta information from image files\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Image::Info qw(imageinfo dim);\n\nmy $info = imageinfo(\"image.jpg\");\nif (my $error = $info->{error}) {\ndie \"Can't parse image info: $error\\n\";\n}\nmy $color = $info->{colortype};\n\nmy $type = imagetype(\"image.jpg\");\nif (my $error = $type->{error}) {\ndie \"Can't determine file type: $error\\n\";\n}\ndie \"No gif files allowed!\" if $type->{filetype} eq 'GIF';\n\nmy($w, $h) = dim($info);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides functions to extract various kinds of meta information from image files.\n\nEXPORTS\nExports nothing by default, but can export the following methods on request:\n\nimageinfo\nimagetype\ndim\nhtmldim\ndeterminefiletype\n\nMETHODS\nThe following functions are provided by the \"Image::Info\" module:\n",
            "subsections": [
                {
                    "name": "image_info",
                    "content": ""
                },
                {
                    "name": "image_info",
                    "content": ""
                },
                {
                    "name": "image_info",
                    "content": "This function takes the name of a file or a file handle as argument and will return one or\nmore hashes (actually hash references) describing the images inside the file. If there is\nonly one image in the file only one hash is returned. In scalar context, only the hash for\nthe first image is returned.\n\nIn case of error, a hash containing the \"error\" key will be returned. The corresponding\nvalue will be an appropriate error message.\n\nIf a reference to a scalar is passed as an argument to this function, then it is assumed\nthat this scalar contains the raw image data directly.\n\nThe \"imageinfo()\" function also take optional key/value style arguments that can influence\nwhat information is returned.\n"
                },
                {
                    "name": "image_type",
                    "content": ""
                },
                {
                    "name": "image_type",
                    "content": "Returns a hash with only one key, \"filetype\". The value will be the type of the file. On\nerror, sets the two keys \"error\" and \"Errno\".\n\nThis function is a dramatically faster alternative to the imageinfo function for situations\nin which you only need to find the image type.\n\nIt uses only the internal file-type detection to do this, and thus does not need to load any\nof the image type-specific driver modules, and does not access to entire file. It also only\nneeds access to the first 11 bytes of the file.\n\nTo maintain some level of compatibility with imageinfo, imagetype returns in the same\nformat, with the same error message style. That is, it returns a HASH reference, with the\n\"$type->{error}\" key set if there was an error.\n\nOn success, the HASH reference will contain the single key \"filetype\", which represents the\ntype of the file, expressed as the type code used for the various drivers ('GIF', 'JPEG',\n'TIFF' and so on).\n\nIf there are multiple images within the file they will be ignored, as this function provides\nonly the type of the overall file, not of the various images within it. This function will\nnot return multiple hashes if the file contains multiple images.\n\nOf course, in all (or at least effectively all) cases the type of the images inside the file\nis going to be the same as that of the file itself.\n"
                },
                {
                    "name": "dim",
                    "content": "Takes an hash as returned from \"imageinfo()\" and returns the dimensions ($width, $height)\nof the image. In scalar context returns the dimensions as a string.\n"
                },
                {
                    "name": "html_dim",
                    "content": "Returns the dimensions as a string suitable for embedding directly into HTML or SVG\n<img>-tags. E.g.:\n\nprint \"<img src=\"...\" @{[htmldim($info)]}>\\n\";\n"
                },
                {
                    "name": "determine_file_format",
                    "content": "Determines the file format from the passed file data (a normal Perl scalar containing the\nfirst bytes of the file), and returns either undef for an unknown file format, or a string\ndescribing the format, like \"BMP\" or \"JPEG\".\n"
                }
            ]
        },
        "Image descriptions": {
            "content": "The \"imageinfo()\" function returns meta information about each image in the form of a reference\nto a hash. The hash keys used are in most cases based on the TIFF element names. All lower case\nkeys are mandatory for all file formats and will always be there unless an error occurred (in\nwhich case the \"error\" key will be present.) Mixed case keys will only be present when the\ncorresponding information element is available in the image.\n\nThe following key names are common for any image format:\n\nfilemediatype\nThis is the MIME type that is appropriate for the given file format. The corresponding value\nis a string like: \"image/png\" or \"image/jpeg\".\n\nfileext\nThe is the suggested file name extension for a file of the given file format. The value is a\n3 letter, lowercase string like \"png\", \"jpg\".\n\nwidth\nThis is the number of pixels horizontally in the image.\n\nheight\nThis is the number of pixels vertically in the image. (TIFF uses the name ImageLength for\nthis field.)\n\ncolortype\nThe value is a short string describing what kind of values the pixels encode. The value can\nbe one of the following:\n\nGray\nGrayA\nRGB\nRGBA\nCMYK\nYCbCr\nCIELab\n\nThese names can also be prefixed by \"Indexed-\" if the image is composed of indexes into a\npalette. Of these, only \"Indexed-RGB\" is likely to occur.\n\nIt is similar to the TIFF field \"PhotometricInterpretation\", but this name was found to be\ntoo long, so we used the PNG inspired term instead.\n\nresolution\nThe value of this field normally gives the physical size of the image on screen or paper.\nWhen the unit specifier is missing then this field denotes the squareness of pixels in the\nimage.\n\nThe syntax of this field is:\n\n<res> <unit>\n<xres> \"/\" <yres> <unit>\n<xres> \"/\" <yres>\n\nThe <res>, <xres> and <yres> fields are numbers. The <unit> is a string like \"dpi\", \"dpm\" or\n\"dpcm\" (denoting \"dots per inch/cm/meter).\n\nSamplesPerPixel\nThis says how many channels there are in the image. For some image formats this number might\nbe higher than the number implied from the \"colortype\".\n\nBitsPerSample\nThis says how many bits are used to encode each of samples. The value is a reference to an\narray containing numbers. The number of elements in the array should be the same as\n\"SamplesPerPixel\".\n\nComment\nTextual comments found in the file. The value is a reference to an array if there are\nmultiple comments found.\n\nInterlace\nIf the image is interlaced, then this tells which interlace method is used.\n\nCompression\nThis tells you which compression algorithm is used.\n\nGamma\nA number.\n\nLastModificationTime\nA ISO date string\n",
            "subsections": []
        },
        "Supported Image Formats": {
            "content": "The following image file formats are supported:\n\nBMP This module supports the Microsoft Device Independent Bitmap format (BMP, DIB, RLE).\n\nFor more information see Image::Info::BMP.\n\nGIF Both GIF87a and GIF89a are supported and the version number is found as \"GIFVersion\" for\nthe first image. GIF files can contain multiple images, and information for all images will\nbe returned if imageinfo() is called in list context. The Netscape-2.0 extension to loop\nanimation sequences is represented by the \"GIFLoop\" key for the first image. The value is\neither \"forever\" or a number indicating loop count.\n\nICO This module supports the Microsoft Windows Icon Resource format (.ico).\n\nJPEG\nFor JPEG files we extract information both from \"JFIF\" and \"Exif\" application chunks.\n\n\"Exif\" is the file format written by most digital cameras. This encode things like\ntimestamp, camera model, focal length, exposure time, aperture, flash usage, GPS position,\netc.\n\nThe \"Exif\" spec can be found at: <http://www.exif.org/specifications.html>.\n\nThe \"colortype\" element may have the following values: \"Gray\", \"YCbCr\", and \"CMYK\". Note\nthat detecting \"RGB\" and \"YCCK\" currently does not work, but will hopefully in future.\n\nPNG Information from IHDR, PLTE, gAMA, pHYs, tEXt, tIME chunks are extracted. The sequence of\nchunks are also given by the \"PNGChunks\" key.\n\nPBM/PGM/PPM\nAll information available is extracted.\n\nSVG Provides a plethora of attributes and metadata of an SVG vector graphic.\n\nTIFF\nThe \"TIFF\" spec can be found at: <http://partners.adobe.com/public/developer/tiff/>\n\nThe EXIF spec can be found at: <http://www.exif.org/specifications.html>\n\nWBMP\nwbmp files have no magic, so cannot be used with the normal Image::Info functions. See\nImage::Info::WBMP for more information.\n\nWEBP\nVP8 (lossy), VP8L (lossless) and VP8X (extended) files are supported. Sets the key\n\"Animation\" to true if the file is an animation. Otherwise sets the key \"Compression\" to\neither \"VP8\" or \"Lossless\".\n\nXBM See Image::Info::XBM for details.\n\nXPM See Image::Info::XPM for details.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "While this module is fine for parsing basic image information like image type, dimensions and\ncolor depth, it is probably not good enough for parsing out more advanced information like EXIF\ndata. If you want an up-to-date and tested EXIF parsing library, please use Image::ExifTool.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Image::Size, Image::ExifTool\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Copyright 1999-2004 Gisle Aas.\n\nSee the CREDITS file for a list of contributors and authors.\n\nTels - (c) 2006 - 2008.\n\nCurrent maintainer: Slaven Rezic - (c) 2008 - 2015.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This library is free software; you can redistribute it and/or modify it under the same terms as\nPerl v5.8.8 itself.\n",
            "subsections": []
        }
    },
    "summary": "Image::Info - Extract meta information from image files",
    "flags": [],
    "examples": [],
    "see_also": []
}