The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
[%#
  # IMPORTANT NOTE
  #   This documentation is generated automatically from source
  #   templates.  Any changes you make here may be lost.
  # 
  #   The 'docsrc' documentation source bundle is available for download
  #   from http://www.template-toolkit.org/docs.html and contains all
  #   the source templates, XML files, scripts, etc., from which the
  #   documentation for the Template Toolkit is built.
-%]
[% META book = 'Modules'
        page = 'Plugin_Image'
%]
[%  WRAPPER toc;
	PROCESS tocitem 
	        title ="SYNOPSIS"
                subs  = [];
	PROCESS tocitem 
	        title ="DESCRIPTION"
                subs  = [];
	PROCESS tocitem 
	        title ="CATCHING ERRORS"
                subs  = [];
	PROCESS tocitem 
	        title ="USING Image::Info"
                subs  = [];
	PROCESS tocitem 
	        title ="AUTHOR"
                subs  = [];
	PROCESS tocitem 
	        title ="VERSION"
                subs  = [];
	PROCESS tocitem 
	        title ="COPYRIGHT"
                subs  = [];
	PROCESS tocitem 
	        title ="SEE ALSO"
                subs  = [];
    END
%]
<!-- Pod to HTML conversion by the Template Toolkit version 2 -->
[% WRAPPER section
    title="SYNOPSIS"
-%]<pre>    [% tt_start_tag %] USE Image(filename) [% tt_end_tag %]
    [% tt_start_tag %] Image.width [% tt_end_tag %]
    [% tt_start_tag %] Image.height [% tt_end_tag %]
    [% tt_start_tag %] Image.size.join(', ') [% tt_end_tag %]
    [% tt_start_tag %] Image.attr [% tt_end_tag %]
    [% tt_start_tag %] Image.tag [% tt_end_tag %]</pre>
[%- END %]
[% WRAPPER section
    title="DESCRIPTION"
-%]<p>
This plugin provides an interface to the Image::Info or Image::Size
modules for determining the size of image files.
</p>
<p>
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.
</p>
<pre>    [% tt_start_tag %] # all these are valid, take your pick [% tt_end_tag %]
    [% tt_start_tag %] USE Image('foo.gif') [% tt_end_tag %]
    [% tt_start_tag %] USE image('bar.gif') [% tt_end_tag %]
    [% tt_start_tag %] USE Image 'ping.gif' [% tt_end_tag %]
    [% tt_start_tag %] USE image(name='baz.gif') [% tt_end_tag %]
    [% tt_start_tag %] USE Image name='pong.gif' [% tt_end_tag %]</pre>
<p>
A &quot;root&quot; parameter can be used to specify the location of the image file:
</p>
<pre>    [% tt_start_tag %] USE Image(root='/path/to/root', name='images/home.png') [% tt_end_tag %]
    # image path: /path/to/root/images/home.png
    # img src: images/home.png</pre>
<p>
In cases where the image path and image url do not match up, specify the
file name directly:
</p>
<pre>    [% tt_start_tag %] USE Image(file='/path/to/home.png', name='/images/home.png') [% tt_end_tag %]</pre>
<p>
The &quot;alt&quot; parameter can be used to specify an alternate name for the
image, for use in constructing an XHTML element (see the tag() method
below).
</p>
<pre>    [% tt_start_tag %] USE Image('home.png', alt=&quot;Home&quot;) [% tt_end_tag %]</pre>
<p>
You can also provide an alternate name for an Image plugin object.
</p>
<pre>    [% tt_start_tag %] USE img1 = image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] USE img2 = image 'bar.gif' [% tt_end_tag %]</pre>
<p>
The 'name' method returns the image file name.
</p>
<pre>    [% tt_start_tag %] img1.name [% tt_end_tag %]     # foo.gif</pre>
<p>
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.
</p>
<pre>    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    width: [% tt_start_tag %] image.width [% tt_end_tag %]
    height: [% tt_start_tag %] image.height [% tt_end_tag %]
    size: [% tt_start_tag %] image.size.join(', ') [% tt_end_tag %]</pre>
<p>
The 'modtime' method returns the ctime of the file in question, suitable
for use with date.format:
</p>
<pre>    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] USE date [% tt_end_tag %]
    [% tt_start_tag %] date.format(image.modtime, &quot;%B, %e %Y&quot;) [% tt_end_tag %]</pre>
<p>
The 'attr' method returns the height and width as HTML/XML attributes.
</p>
<pre>    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.attr [% tt_end_tag %]</pre>
<p>
Typical output:
</p>
<pre>    width=&quot;60&quot; height=&quot;20&quot;</pre>
<p>
The 'tag' method returns a complete XHTML tag referencing the image.
</p>
<pre>    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.tag [% tt_end_tag %]</pre>
<p>
Typical output:
</p>
<pre>    &lt;img src=&quot;foo.gif&quot; width=&quot;60&quot; height=&quot;20&quot; alt=&quot;&quot; /&gt;</pre>
<p>
You can provide any additional attributes that should be added to the 
XHTML tag.
</p>
<pre>    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.tag(class=&quot;logo&quot; alt=&quot;Logo&quot;) [% tt_end_tag %]</pre>
<p>
Typical output:
</p>
<pre>    &lt;img src=&quot;foo.gif&quot; width=&quot;60&quot; height=&quot;20&quot; alt=&quot;Logo&quot; class=&quot;logo&quot; /&gt;</pre>
<p>
Note that the 'alt' attribute is mandatory in a strict XHTML 'img'
element (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 'tag' method, as shown in the previous example, or as an argument
</p>
<pre>    [% tt_start_tag %] USE image('foo.gif', alt='Logo') [% tt_end_tag %]</pre>
[%- END %]
[% WRAPPER section
    title="CATCHING ERRORS"
-%]<p>
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.
</p>
<pre>    [% tt_start_tag %] TRY;
         image.width;
       CATCH;
         error;      # print error
       END
    [% tt_end_tag %]</pre>
[%- END %]
[% WRAPPER section
    title="USING Image::Info"
-%]<p>
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 [% ttlink('Image::Info') -%] for more details
-- the types of methods available depend on the type of image.
These additional methods will always include the following:
</p>
<ul>
<li><b>file_media_type</b><br>
<p>
This is the MIME type that is appropriate for the given file format.
The corresponding value is a string like: &quot;image/png&quot; or &quot;image/jpeg&quot;.
</p>

<li><b>file_ext</b><br>
<p>
The is the suggested file name extention for a file of the given
file format.  The value is a 3 letter, lowercase string like
&quot;png&quot;, &quot;jpg&quot;.
</p>

<li><b>color_type</b><br>
<p>
The value is a short string describing what kind of values the pixels
encode.  The value can be one of the following:
</p>
<pre>  Gray
  GrayA
  RGB
  RGBA
  CMYK
  YCbCr
  CIELab</pre>
<p>
These names can also be prefixed by &quot;Indexed-&quot; if the image is
composed of indexes into a palette.  Of these, only &quot;Indexed-RGB&quot; is
likely to occur.
</p>
<p>
(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.)
</p>

<li><b>resolution</b><br>
<p>
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.
</p>
<p>
The syntax of this field is:
</p>
<pre>   &lt;res&gt; &lt;unit&gt;
   &lt;xres&gt; &quot;/&quot; &lt;yres&gt; &lt;unit&gt;
   &lt;xres&gt; &quot;/&quot; &lt;yres&gt;</pre>
<p>
The &lt;res&gt;, &lt;xres&gt; and &lt;yres&gt; fields are
numbers.  The &lt;unit&gt; is a string like <code>'dpi'</code>, <code>'dpm'</code> or
<code>'dpcm'</code> (denoting &quot;dots per inch/cm/meter).
</p>

<li><b>SamplesPerPixel</b><br>
<p>
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
<code>'color_type'</code>.
</p>

<li><b>BitsPerSample</b><br>
<p>
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 <code>'SamplesPerPixel'</code>.
</p>

<li><b>Comment</b><br>
<p>
Textual comments found in the file.  The value is a reference to an
array if there are multiple comments found.
</p>

<li><b>Interlace</b><br>
<p>
If the image is interlaced, then this tell which interlace method is
used.
</p>

<li><b>Compression</b><br>
<p>
This tell which compression algorithm is used.
</p>

<li><b>Gamma</b><br>
<p>
A number.
</p>

</ul>
[%- END %]
[% WRAPPER section
    title="AUTHOR"
-%]<p>
Andy Wardley &lt;abw@wardley.org&gt;
</p>
<p>
[% ttlink('http://wardley.org/', 'http://wardley.org/') -%]
</p>
[%- END %]
[% WRAPPER section
    title="VERSION"
-%]<p>
1.21, distributed as part of the
Template Toolkit version 2.19, released on 27 April 2007.
</p>
[%- END %]
[% WRAPPER section
    title="COPYRIGHT"
-%]<pre>  Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.</pre>
<p>
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
</p>
[%- END %]
[% WRAPPER section
    title="SEE ALSO"
-%]<p>
[% ttlink('Template::Plugin', 'Template::Plugin') -%]
</p>
[%- END %]