1Template::Plugin::ImageU(s3e)r Contributed Perl DocumentaTteimopnlate::Plugin::Image(3)
2
3
4
6 Template::Plugin::Image - Plugin access to image sizes
7
9 [% USE Image(filename) %]
10 [% Image.width %]
11 [% Image.height %]
12 [% Image.size.join(', ') %]
13 [% Image.attr %]
14 [% Image.tag %]
15
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 ele‐
60 ment 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 ctime of the file in question, suit‐
68 able for use with date.format:
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' ele‐
103 ment (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
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 TRY...CATCH
112 block to catch any potential errors.
113
114 [% TRY;
115 image.width;
116 CATCH;
117 error; # print error
118 END
119 %]
120
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; see Image::Info for more details --
127 the types of methods available depend on the type of image. 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 for‐
132 mat. The corresponding value is a string like: "image/png" or
133 "image/jpeg".
134
135 file_ext
136 The is the suggested file name extention for a file of the given
137 file 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 pix‐
142 els 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 com‐
153 posed 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
157 this name was found to be too long, so we used the PNG inpired term
158 instead.)
159
160 resolution
161 The value of this field normally gives the physical size of the
162 image on screen or paper. When the unit specifier is missing then
163 this field 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 a
172 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
178 the "color_type".
179
180 BitsPerSample
181 This says how many bits are used to encode each of samples. The
182 value is a reference to an array containing numbers. The number of
183 elements 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 tell which interlace method
191 is used.
192
193 Compression
194 This tell which compression algorithm is used.
195
196 Gamma
197 A number.
198
200 Andy Wardley <abw@wardley.org>
201
202 <http://wardley.org/⎪http://wardley.org/>
203
205 1.21, distributed as part of the Template Toolkit version 2.18,
206 released on 09 February 2007.
207
209 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
210
211 This module is free software; you can redistribute it and/or modify it
212 under the same terms as Perl itself.
213
215 Template::Plugin
216
217
218
219perl v5.8.8 2007-02-09 Template::Plugin::Image(3)