NAME
App::ZofCMS::Plugin::AutoIMGSize - automatically get image sizes and generate appropriate <img> tags
SYNOPSIS
In your Main Config or ZofCMS Template file:
plugins => [ qw/AutoIMGSize/ ],
plug_auto_img_size => {
imgs => {
logo => 'pics/top_logo.png'
kitteh => 'pics/kitteh.jpg',
blah => { 'somewhere/there.jpg' => ' class="foo"' },
},
},
In your HTML::Template template:
Logo: <tmpl_var name="img_logo">
Kitteh: <tmpl_var name="img_kitteh">
blah: <tmpl_var name="img_blah">
DESCRIPTION
The module is a plugin for App::ZofCMS. It provides means to generate HTML <img ... >
tags with automatic image size generation, i.e. the plugin gets the size of the image from the file. Personally, I use it in templates where the size of the image is unknown, if the image is static and you can physically type in the address, it would be saner to do so.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
MAIN CONFIG FILE OR ZofCMS TEMPLATE KEYS
plugins
plugins => [ qw/AutoIMGSize/ ],
You would obvisouly want to add the plugin to the list of plugins to run. Play with priorities if you are loading image paths dynamically.
plug_auto_img_size
plug_auto_img_size => {
xhtml => 1,
t_prefix => 'img_',
imgs => {
logo => 'pics/logo.png',
kitteh => { 'pics/kitteh.jpg' => ' class="kitteh' },
},
},
The plug_auto_img_size
first-level Main Config file or ZofCMS Template file is what makes the plugin run. If you specify this key in both ZofCMS Template and Main Config file then keys set in ZofCMS Template will override the ones set in Main Config file. Note: the imgs
key will be completely overridden.
The key takes a hashref as a value. Possible keys/values of that hashref are as follows:
imgs
imgs => [ qw/foo.jpg bar.jpg/ ],
#same as
imgs => {
'foo.jpg' => 'foo.jpg',
'bar.jpg' => 'bar.jpg',
},
Mandatory. The imgs
key takes either an arrayref or a hashref as a value. If the value is an arrayref, it will be converted to a hashref where keys and values are the same.
The key in the hashref specifies the "name" of the key in {t}
ZofCMS Template special key to which the t_prefix
(see below) will be prepended. The value specifies the image filename relative to ZofCMS index.pl
file (root dir of your website, basically). The value of each key can be either a string or a hashref. If it's a string, it will be taken as a filename of the image. If it is a hashref it must contain only one key/value pair; the key of that hashref will be taken as a filename of the image and the value will be taken as extra HTML attributes to insert into <img>
tag. Note that the value, in this case, should begin with a space as to not merge with the width/height attributes. Note 2: unless the value is a hashref, the alt=""
attribute will be set to an empty string; otherwise you must include it in "extra" html attributes. Here are a few examples (which assume that t_prefix
(see below) is set to its default value: img_
; and size of the image is 500px x 500px):
# ZofCMS template:
imgs => [ qw/foo.jpg/ ]
# HTML::Template template:
<tmpl_var name="img_foo.jpg">
# Resulting HTML code:
<img src="/foo.jpg" width="500" height="500" alt="">
Note: that image src=""
attribute is made relative to root path of your website (i.e. starts with a slash /
character).
# ZofCMS tempalte:
imgs => { foo => 'pics/foo.jpg' },
# HTML::Template template:
<tmpl_var name="img_foo">
# Resulting HTML code:
<img src="/pics/foo.jpg" width="500" height="500" alt="">
Now with custom attributes (note the leading space before alt=""
attribute):
# ZofCMS template:
imgs => { foo => { 'pics/foo.jpg' => ' alt="foos" class="foos"' } }
# HTML::Template template:
<tmpl_var name="img_foo">
# Resulting HTML code:
<img src="/pics/foo.jpg" width="500" height="500" alt="foos" class="foos">
Note: if plugin cannot find your image file then the <img>
tag will be replaced with ERROR: Not found
.
t_prefix
t_prefix => 'img_',
Optional. The t_prefix
takes a string as a value, this string will be prepended to the "name" of your images in {t}
ZofCMS Template special key. In other words, if you set t_prefix => 'img_', imgs => { foo => 'pics/bar.jpg' }
, then in your HTML::Template template you'd insert your image with <tmpl_var name="img_foo">
. Defaults to: img_
(note the underscore (_
) at the end)
xhtml
xhtml => 1,
Optional. When set to a true value the <img>
tag will be closed with />
. When set to a false value the <img>
tag will be closed with >
. Default to: 0
(false)
DEPENDENCIES
The module relies on Image::Size to get image sizes.
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
BUGS
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org
AUTHOR
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
LICENSE
You can use and distribute this module under the same terms as Perl itself. See the LICENSE
file included in this distribution for complete details.