16 Aug 2022 07:02:05 UTC
- Distribution: Template-Toolkit
- Module version: 3.100
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (74)
- Testers (1304 / 27 / 0)
- KwaliteeBus factor: 3
- % Coverage
- License: perl_5
- Download (503.85KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:65 non-PAUSE users
- Andy Wardley
- CATCHING ERRORS
- USING Image::Info
- SEE ALSO
Template::Plugin::Image - Plugin access to image sizes
[% USE Image(filename) %] [% Image.width %] [% Image.height %] [% Image.size.join(', ') %] [% Image.attr %] [% Image.tag %]
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' %]
rootparameter can be used to specify the location of the image file:
[% USE Image(root='/path/to/root', name='images/home.png') %] # image path: /path/to/root/images/home.png # img src: images/home.png
In cases where the image path and image url do not match up, specify the file name directly:
[% USE Image(file='/path/to/home.png', name='/images/home.png') %]
altparameter can be used to specify an alternate name for the image, for use in constructing an XHTML element (see the
[% USE Image('home.png', alt="Home") %]
You can also provide an alternate name for an
[% USE img1 = image 'foo.gif' %] [% USE img2 = image 'bar.gif' %]
namemethod returns the image file name.
[% img1.name %] # foo.gif
heightmethods return the width and height of the image, respectively. The
sizemethod 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(', ') %]
modtimemethod returns the modification time of the file in question, suitable for use with the Date plugin, for example:
[% USE image 'foo.gif' %] [% USE date %] [% date.format(image.modtime, "%B, %e %Y") %]
attrmethod returns the height and width as HTML/XML attributes.
[% USE image 'foo.gif' %] [% image.attr %]
tagmethod returns a complete XHTML tag referencing the image.
[% USE image 'foo.gif' %] [% image.tag %]
<img src="foo.gif" width="60" height="20" alt="" />
You can provide any additional attributes that should be added to the XHTML tag.
[% USE image 'foo.gif' %] [% image.tag(class="logo" alt="Logo") %]
<img src="foo.gif" width="60" height="20" alt="Logo" class="logo" />
Note that the
altattribute is mandatory in a strict XHTML
imgelement (even if it's empty) so it is always added even if you don't explicitly provide a value for it. You can do so as an argument to the
tagmethod, as shown in the previous example, or as an argument
[% USE image('foo.gif', alt='Logo') %]
If the image file cannot be found then the above methods will throw an
Imageerror. You can enclose calls to these methods in a
TRY...CATCHblock 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
tag. These additional methods are named after the elements that Image::Info retrieves from the image itself. The types of methods available depend on the type of image (see Image::Info for more details). These additional methods will always include the following:
This is the MIME type that is appropriate for the given file format. The corresponding value is a string like: "
image/png" or "
The is the suggested file name extension for a file of the given file format. The value is a 3 letter, lowercase string like "
The value is a short string describing what kind of values the pixels encode. The value can be one of 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 inspired term instead.)
The value of this field normally gives the physical size of the image on screen or paper. When the unit specifier is missing then this field denotes the squareness of pixels in the image.
The syntax of this field is:
<res> <unit> <xres> "/" <yres> <unit> <xres> "/" <yres>
<yres>fields are numbers. The
<unit>is a string like
dpcm(denoting "dots per inch/cm/meter).
This says how many channels there are in the image. For some image formats this number might be higher than the number implied from the
This says how many bits are used to encode each of samples. The value is a reference to an array containing numbers. The number of elements in the array should be the same as
Textual comments found in the file. The value is a reference to an array if there are multiple comments found.
If the image is interlaced, then this returns the interlace type.
This returns the name of the compression algorithm is used.
A number indicating the gamma curve of the image (e.g. 2.2)
Andy Wardley <email@example.com> http://wardley.org/
Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Template::Toolkit, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Template::Toolkit
For more information on module installation, please visit the detailed CPAN module installation guide.
|s||Focus search bar|
|?||Bring up this help dialog|
|g p||Go to pull requests|
|g i||go to github issues (only if github is preferred repository)|
|g a||Go to author|
|g c||Go to changes|
|g i||Go to issues|
|g d||Go to dist|
|g r||Go to repository/SCM|
|g s||Go to source|
|g b||Go to file browse|