1Template::Plugin::ImageU(s3e)r Contributed Perl DocumentaTteimopnlate::Plugin::Image(3)
2
3
4

NAME

6       Template::Plugin::Image - Plugin access to image sizes
7

SYNOPSIS

9           [% USE Image(filename) %]
10           [% Image.width %]
11           [% Image.height %]
12           [% Image.size.join(', ') %]
13           [% Image.attr %]
14           [% Image.tag %]
15

DESCRIPTION

17       This plugin provides an interface to the Image::Info or Image::Size
18       modules for determining the size of image files.
19
20       You can specify the plugin name as either '"Image"' or '"image"'.  The
21       plugin object created will then have the same name.  The file name of
22       the image should be specified as a positional or named argument.
23
24           [% # all these are valid, take your pick %]
25           [% USE Image('foo.gif') %]
26           [% USE image('bar.gif') %]
27           [% USE Image 'ping.gif' %]
28           [% USE image(name='baz.gif') %]
29           [% USE Image name='pong.gif' %]
30
31       A "root" parameter can be used to specify the location of the image
32       file:
33
34           [% USE Image(root='/path/to/root', name='images/home.png') %]
35           # image path: /path/to/root/images/home.png
36           # img src: images/home.png
37
38       In cases where the image path and image url do not match up, specify
39       the file name directly:
40
41           [% USE Image(file='/path/to/home.png', name='/images/home.png') %]
42
43       The "alt" parameter can be used to specify an alternate name for the
44       image, for use in constructing an XHTML element (see the tag() method
45       below).
46
47           [% USE Image('home.png', alt="Home") %]
48
49       You can also provide an alternate name for an "Image" plugin object.
50
51           [% USE img1 = image 'foo.gif' %]
52           [% USE img2 = image 'bar.gif' %]
53
54       The "name" method returns the image file name.
55
56           [% img1.name %]     # foo.gif
57
58       The "width" and "height" methods return the width and height of the
59       image, respectively.  The "size" method returns a reference to a 2
60       element list containing the width and height.
61
62           [% USE image 'foo.gif' %]
63           width: [% image.width %]
64           height: [% image.height %]
65           size: [% image.size.join(', ') %]
66
67       The "modtime" method returns the modification time of the file in
68       question, suitable for use with the Date plugin, for example:
69
70           [% USE image 'foo.gif' %]
71           [% USE date %]
72           [% date.format(image.modtime, "%B, %e %Y") %]
73
74       The "attr" method returns the height and width as HTML/XML attributes.
75
76           [% USE image 'foo.gif' %]
77           [% image.attr %]
78
79       Typical output:
80
81           width="60" height="20"
82
83       The "tag" method returns a complete XHTML tag referencing the image.
84
85           [% USE image 'foo.gif' %]
86           [% image.tag %]
87
88       Typical output:
89
90           <img src="foo.gif" width="60" height="20" alt="" />
91
92       You can provide any additional attributes that should be added to the
93       XHTML tag.
94
95           [% USE image 'foo.gif' %]
96           [% image.tag(class="logo" alt="Logo") %]
97
98       Typical output:
99
100           <img src="foo.gif" width="60" height="20" alt="Logo" class="logo" />
101
102       Note that the "alt" attribute is mandatory in a strict XHTML "img"
103       element (even if it's empty) so it is always added even if you don't
104       explicitly provide a value for it.  You can do so as an argument to the
105       "tag" method, as shown in the previous example, or as an argument
106
107           [% USE image('foo.gif', alt='Logo') %]
108

CATCHING ERRORS

110       If the image file cannot be found then the above methods will throw an
111       "Image" error.  You can enclose calls to these methods in a
112       "TRY...CATCH" block to catch any potential errors.
113
114           [% TRY;
115                image.width;
116              CATCH;
117                error;      # print error
118              END
119           %]
120

USING Image::Info

122       At run time, the plugin tries to load Image::Info in preference to
123       Image::Size. If Image::Info is found, then some additional methods are
124       available, in addition to "size", "width", "height", "attr", and "tag".
125       These additional methods are named after the elements that Image::Info
126       retrieves from the image itself. The types of methods available depend
127       on the type of image (see Image::Info for more details). These
128       additional methods will always include the following:
129
130   file_media_type
131       This is the MIME type that is appropriate for the given file format.
132       The corresponding value is a string like: ""image/png"" or
133       ""image/jpeg"".
134
135   file_ext
136       The is the suggested file name extension for a file of the given file
137       format.  The value is a 3 letter, lowercase string like ""png"",
138       ""jpg"".
139
140   color_type
141       The value is a short string describing what kind of values the pixels
142       encode.  The value can be one of the following:
143
144           Gray
145           GrayA
146           RGB
147           RGBA
148           CMYK
149           YCbCr
150           CIELab
151
152       These names can also be prefixed by ""Indexed-"" if the image is
153       composed of indexes into a palette.  Of these, only ""Indexed-RGB"" is
154       likely to occur.
155
156       (It is similar to the TIFF field PhotometricInterpretation, but this
157       name was found to be too long, so we used the PNG inspired term
158       instead.)
159
160   resolution
161       The value of this field normally gives the physical size of the image
162       on screen or paper. When the unit specifier is missing then this field
163       denotes the squareness of pixels in the image.
164
165       The syntax of this field is:
166
167          <res> <unit>
168          <xres> "/" <yres> <unit>
169          <xres> "/" <yres>
170
171       The "<res>", "<xres>" and "<yres>" fields are numbers.  The "<unit>" is
172       a string like "dpi", "dpm" or "dpcm" (denoting "dots per
173       inch/cm/meter).
174
175   SamplesPerPixel
176       This says how many channels there are in the image.  For some image
177       formats this number might be higher than the number implied from the
178       "color_type".
179
180   BitsPerSample
181       This says how many bits are used to encode each of samples.  The value
182       is a reference to an array containing numbers. The number of elements
183       in the array should be the same as "SamplesPerPixel".
184
185   Comment
186       Textual comments found in the file.  The value is a reference to an
187       array if there are multiple comments found.
188
189   Interlace
190       If the image is interlaced, then this returns the interlace type.
191
192   Compression
193       This returns the name of the compression algorithm is used.
194
195   Gamma
196       A number indicating the gamma curve of the image (e.g. 2.2)
197

AUTHOR

199       Andy Wardley <abw@wardley.org> <http://wardley.org/>
200
202       Copyright (C) 1996-2022 Andy Wardley.  All Rights Reserved.
203
204       This module is free software; you can redistribute it and/or modify it
205       under the same terms as Perl itself.
206

SEE ALSO

208       Template::Plugin, Image::Info
209
210
211
212perl v5.38.0                      2023-07-21        Template::Plugin::Image(3)
Impressum