Template::Plugin::Image - Plugin access to image sizes |
Template::Plugin::Image - Plugin access to image sizes
[% USE Image(filename) %] [% Image.width %] [% Image.height %] [% Image.size.join(', ') %] [% Image.attr %] [% Image.tag %]
This plugin provides an interface to the Image::Info or Image::Size modules for determining the size of image files.
You can specify the plugin name as either 'Image' or 'image'. The plugin object created will then have the same name. The file name of the image should be specified as a positional or named argument.
[% # all these are valid, take your pick %] [% USE Image('foo.gif') %] [% USE image('bar.gif') %] [% USE Image 'ping.gif' %] [% USE image(name='baz.gif') %] [% USE Image name='pong.gif' %]
You can also provide an alternate name for an Image plugin object.
[% USE img1 = image 'foo.gif' %] [% USE img2 = image 'bar.gif' %]
The 'width' and 'height' methods return the width and height of the image, respectively. The 'size' method returns a reference to a 2 element list containing the width and height.
[% USE image 'foo.gif' %] width: [% image.width %] height: [% image.height %] size: [% image.size.join(', ') %]
The 'attr' method returns the height and width as HTML/XML attributes.
[% USE image 'foo.gif' %] [% image.attr %]
Typical output:
width="60" height="20"
The 'tag' method returns a complete XHTML tag referencing the image.
[% USE image 'foo.gif' %] [% image.tag %]
Typical output:
<img src="foo.gif" width="60" height="20" />
You can provide any additional attributes that should be added to the XHTML tag.
[% USE image 'foo.gif' %] [% image.tag(border=0, class="logo") %]
Typical output:
<img src="foo.gif" width="60" height="20" border="0" class="logo" />
The 'modtime' method returns the ctime of the file in question, suitable for use with date.format:
[% USE image 'foo.gif' %] [% USE date %] [% date.format(image.modtime, "%B, %e %Y") %]
If the image file cannot be found then the above methods will throw an 'Image' error. You can enclose calls to these methods in a TRY...CATCH block to catch any potential errors.
[% TRY; image.width; CATCH; error; # print error END %]
At run time, the plugin tries to load Image::Info in preference to Image::Size. If Image::Info is found, then some additional methods are available, in addition to 'size', 'width', 'height', 'attr', and 'tag'. These additional methods are named after the elements that Image::Info retrieves from the image itself; see the Image::Info manpage for more details -- the types of methods available depend on the type of image. These additional methods will always include 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 inpired term instead.)
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).
color_type
.
SamplesPerPixel
.
Andy Wardley <abw@andywardley.com>
http://www.andywardley.com/|http://www.andywardley.com/
1.08, distributed as part of the Template Toolkit version 2.10, released on 24 July 2003.
Copyright (C) 1996-2003 Andy Wardley. All Rights Reserved. Copyright (C) 1998-2002 Canon Research Centre Europe Ltd.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Template::Plugin::Image - Plugin access to image sizes |