[%# # 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 %] [% WRAPPER section title="SYNOPSIS" -%]
    [% 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 %]
[%- END %] [% WRAPPER section title="DESCRIPTION" -%]

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.

    [% 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 %]

You can also provide an alternate name for an Image plugin object.

    [% tt_start_tag %] USE img1 = image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] USE img2 = image 'bar.gif' [% tt_end_tag %]

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.

    [% 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 %]

The 'attr' method returns the height and width as HTML/XML attributes.

    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.attr [% tt_end_tag %]

Typical output:

    width="60" height="20"

The 'tag' method returns a complete XHTML tag referencing the image.

    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.tag [% tt_end_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.

    [% tt_start_tag %] USE image 'foo.gif' [% tt_end_tag %]
    [% tt_start_tag %] image.tag(border=0, class="logo") [% tt_end_tag %]

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:

    [% 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, "%B, %e %Y") [% tt_end_tag %]
[%- END %] [% WRAPPER section title="CATCHING ERRORS" -%]

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.

    [% tt_start_tag %] TRY;
         image.width;
       CATCH;
         error;      # print error
       END
    [% tt_end_tag %]
[%- END %] [% WRAPPER section title="USING Image::Info" -%]

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:

[%- END %] [% WRAPPER section title="AUTHOR" -%]

Andy Wardley <abw@andywardley.com>

[% ttlink('http://www.andywardley.com/', 'http://www.andywardley.com/') -%]

[%- END %] [% WRAPPER section title="VERSION" -%]

1.14, distributed as part of the Template Toolkit version 2.14, released on 04 October 2004.

[%- END %] [% WRAPPER section title="COPYRIGHT" -%]
  Copyright (C) 1996-2004 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.

[%- END %] [% WRAPPER section title="SEE ALSO" -%]

[% ttlink('Template::Plugin', 'Template::Plugin') -%]

[%- END %]