++ed by:
1 non-PAUSE user
Author image Oleg A. Mamontov
and 2 contributors


Dancer::Plugin::Thumbnail - Easy thumbnails creating with Dancer and GD


Version 0.16


 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 };


thumbnail ( $file, \@operations, \%options )

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:

         cache: var/cache
         compression: 7
         quality: 50

crop ( $file, \%arguments, \%options )

This is shortcut (syntax sugar) fully equivalent to call:

thumbnail ( $file, [ crop => \%arguments ], \%options )

Arguments includes:

w | width

Desired width (optional, default not to crop by horizontal).

h | height

Desired height (optional, default not to crop by vertical).

a | anchors

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).

resize ( $file, \%arguments, \%options )

This is shortcut and fully equivalent to call:

thumbnail ( $file, [ resize => \%arguments ], \%options )

Arguments includes:

w | width

Desired width (optional, default not to resize by horizontal).

h | height

Desired height (optional, default not to resize by vertical).

s | scale

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>


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.


You can find documentation for this module with the perldoc command.

    perldoc Dancer::Plugin::Thumbnail

You can also look for information at:


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.