{
    "mode": "perldoc",
    "parameter": "Template::Plugin::Image",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Template%3A%3APlugin%3A%3AImage/json",
    "generated": "2026-06-13T22:55:26Z",
    "synopsis": "[% USE Image(filename) %]\n[% Image.width %]\n[% Image.height %]\n[% Image.size.join(', ') %]\n[% Image.attr %]\n[% Image.tag %]",
    "sections": {
        "NAME": {
            "content": "Template::Plugin::Image - Plugin access to image sizes\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "[% USE Image(filename) %]\n[% Image.width %]\n[% Image.height %]\n[% Image.size.join(', ') %]\n[% Image.attr %]\n[% Image.tag %]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This plugin provides an interface to the Image::Info or Image::Size modules for determining the\nsize of image files.\n\nYou can specify the plugin name as either '\"Image\"' or '\"image\"'. The plugin object created will\nthen have the same name. The file name of the image should be specified as a positional or named\nargument.\n\n[% # all these are valid, take your pick %]\n[% USE Image('foo.gif') %]\n[% USE image('bar.gif') %]\n[% USE Image 'ping.gif' %]\n[% USE image(name='baz.gif') %]\n[% USE Image name='pong.gif' %]\n\nA \"root\" parameter can be used to specify the location of the image file:\n\n[% USE Image(root='/path/to/root', name='images/home.png') %]\n# image path: /path/to/root/images/home.png\n# img src: images/home.png\n\nIn cases where the image path and image url do not match up, specify the file name directly:\n\n[% USE Image(file='/path/to/home.png', name='/images/home.png') %]\n\nThe \"alt\" parameter can be used to specify an alternate name for the image, for use in\nconstructing an XHTML element (see the \"tag()\" method below).\n\n[% USE Image('home.png', alt=\"Home\") %]\n\nYou can also provide an alternate name for an \"Image\" plugin object.\n\n[% USE img1 = image 'foo.gif' %]\n[% USE img2 = image 'bar.gif' %]\n\nThe \"name\" method returns the image file name.\n\n[% img1.name %]     # foo.gif\n\nThe \"width\" and \"height\" methods return the width and height of the image, respectively. The\n\"size\" method returns a reference to a 2 element list containing the width and height.\n\n[% USE image 'foo.gif' %]\nwidth: [% image.width %]\nheight: [% image.height %]\nsize: [% image.size.join(', ') %]\n\nThe \"modtime\" method returns the modification time of the file in question, suitable for use\nwith the Date plugin, for example:\n\n[% USE image 'foo.gif' %]\n[% USE date %]\n[% date.format(image.modtime, \"%B, %e %Y\") %]\n\nThe \"attr\" method returns the height and width as HTML/XML attributes.\n\n[% USE image 'foo.gif' %]\n[% image.attr %]\n\nTypical output:\n\nwidth=\"60\" height=\"20\"\n\nThe \"tag\" method returns a complete XHTML tag referencing the image.\n\n[% USE image 'foo.gif' %]\n[% image.tag %]\n\nTypical output:\n\n<img src=\"foo.gif\" width=\"60\" height=\"20\" alt=\"\" />\n\nYou can provide any additional attributes that should be added to the XHTML tag.\n\n[% USE image 'foo.gif' %]\n[% image.tag(class=\"logo\" alt=\"Logo\") %]\n\nTypical output:\n\n<img src=\"foo.gif\" width=\"60\" height=\"20\" alt=\"Logo\" class=\"logo\" />\n\nNote that the \"alt\" attribute is mandatory in a strict XHTML \"img\" element (even if it's empty)\nso it is always added even if you don't explicitly provide a value for it. You can do so as an\nargument to the \"tag\" method, as shown in the previous example, or as an argument\n\n[% USE image('foo.gif', alt='Logo') %]\n",
            "subsections": []
        },
        "CATCHING ERRORS": {
            "content": "If the image file cannot be found then the above methods will throw an \"Image\" error. You can\nenclose calls to these methods in a \"TRY...CATCH\" block to catch any potential errors.\n\n[% TRY;\nimage.width;\nCATCH;\nerror;      # print error\nEND\n%]\n\nUSING Image::Info\nAt run time, the plugin tries to load Image::Info in preference to Image::Size. If Image::Info\nis found, then some additional methods are available, in addition to \"size\", \"width\", \"height\",\n\"attr\", and \"tag\". These additional methods are named after the elements that Image::Info\nretrieves from the image itself. The types of methods available depend on the type of image (see\nImage::Info for more details). These additional methods will always include the following:\n\nfilemediatype\nThis is the MIME type that is appropriate for the given file format. The corresponding value is\na 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 3\nletter, lowercase string like \"\"png\"\", \"\"jpg\"\".\n\ncolortype\nThe value is a short string describing what kind of values the pixels encode. The value can be\none 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\n(It is similar to the TIFF field PhotometricInterpretation, but this name was found to be too\nlong, 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. When\nthe unit specifier is missing then this field denotes the squareness of pixels in the image.\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\",\n\"dpm\" or \"dpcm\" (denoting \"dots per inch/cm/meter).\n",
            "subsections": [
                {
                    "name": "SamplesPerPixel",
                    "content": "This says how many channels there are in the image. For some image formats this number might be\nhigher than the number implied from the \"colortype\".\n"
                },
                {
                    "name": "BitsPerSample",
                    "content": "This says how many bits are used to encode each of samples. The value is a reference to an array\ncontaining numbers. The number of elements in the array should be the same as \"SamplesPerPixel\".\n"
                },
                {
                    "name": "Comment",
                    "content": "Textual comments found in the file. The value is a reference to an array if there are multiple\ncomments found.\n"
                },
                {
                    "name": "Interlace",
                    "content": "If the image is interlaced, then this returns the interlace type.\n"
                },
                {
                    "name": "Compression",
                    "content": "This returns the name of the compression algorithm is used.\n"
                },
                {
                    "name": "Gamma",
                    "content": "A number indicating the gamma curve of the image (e.g. 2.2)\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "Andy Wardley <abw@wardley.org> <http://wardley.org/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Template::Plugin, Image::Info\n",
            "subsections": []
        }
    },
    "summary": "Template::Plugin::Image - Plugin access to image sizes",
    "flags": [],
    "examples": [],
    "see_also": []
}