Dancer::Plugin::Thumbnail - Easy thumbnails creating with Dancer and GD
Version 0.07
use Dancer; use Dancer::Plugin::Thumbnail; # simple resize get '/resized/:width/:image' => sub { resize param('image') => { w => param 'width' }; } # simple crop get '/cropped/:width/:image' => sub { crop param('image') => { w => param 'width' }; } # more complex get '/thumb/:w/:h/:image' => sub { thumbnail param('image') => [ crop => { w => 200, h => 200, a => 'lt' }, resize => { w => param('w'), h => param('h'), s => 'min' }, ], { format => 'jpeg', quality => 90 }; }
Makes thumbnail image from original file by chain of graphic operations. Image file name may be an absolute path or relative from config->{'public'}. Each operation is a reference for two elements array. First element is an operation name (currently supported 'resize' and 'crop') and second is operation arguments as hash reference (described in appropriate operation section).
After operations chain completed final image creates with supplied options:
Directory name for storing final results. Undefined setting (default) breaks caching and isn't recommended for any serious production usage. Relative cache directory will be prefixed with config->{'appdir'} automatically. Cache path is generated from original file name, its modification time, operations with arguments and an options. If you are worried about cache garbage collecting you can create a simple cron job like:
find /cache/path -type f -not -newerat '1 week ago' -delete
Specifies output image format. Supported formats are 'gif', 'jpeg' and 'png'. Special format 'auto' (which is default) creates the same format as original image has.
PNG compression level. From '0' (no compression) to '9' (maximum). Default is '-1' (default GD compression level for PNG creation).
JPEG quality specifications. From '0' (the worse) to '100' (the best). Default is 'undef' (default GD quality for JPEG creation).
Defaults for these options can be specified in config.yml:
plugins: Thumbnail: cache: var/cache compression: 7 quality: 50
This is shortcut (syntax sugar) fully equivalent to call:
thumbnail ( $file, [ crop => \%arguments ], \%options )
Arguments includes:
Desired width (optional, default not to crop by horizontal).
Desired height (optional, default not to crop by vertical).
Two characters string which indicates desired fragment of original image. First character can be one of 'l/c/r' (left/right/center), and second - 't/m/b' (top/middle/bottom). Default is 'cm' (centered by horizontal and vertical).
This is shortcut and fully equivalent to call:
thumbnail ( $file, [ resize => \%arguments ], \%options )
Desired width (optional, default not to resize by horizontal).
Desired height (optional, default not to resize by vertical).
The operation always keeps original image proportions. Horizontal and vertical scales calculates separately and 'scale' argument helps to select maximum or minimum from "canditate" values. Argument can be 'min' or 'max' (which is default).
Oleg A. Mamontov, <oleg at mamontov.net>
<oleg at mamontov.net>
Please report any bugs or feature requests to bug-dancer-plugin-thumbnail at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Thumbnail. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dancer-plugin-thumbnail at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::Thumbnail
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Thumbnail
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Plugin-Thumbnail
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Plugin-Thumbnail
Search CPAN
http://search.cpan.org/dist/Dancer-Plugin-Thumbnail/
Copyright 2011 Oleg A. Mamontov.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Dancer::Plugin::Thumbnail, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::Thumbnail
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::Thumbnail
For more information on module installation, please visit the detailed CPAN module installation guide.