Catalyst::View::Thumbnail::Simple - Simple Catalyst view class for thumbnailing images
# in a view class of your application package MyApp::View::Thumbnailer; use base 'Catalyst::View::Thumbnail::Simple; 1; # in your controller my $raw_image_data = $image->data; # scale $c->stash( image => \$raw_image_data, image_size => 150 ); $c->forward('View::Thumbnailer'); # crop into a square and scale $c->stash( image => \$raw_image_data, image_size => 300, square => 1 ); $c->forward('View::Thumbnailer'); # scale and transcode image to png $c->stash( image => \$raw_image_data, image_size => 150, image_type => 'png' );
This module is a View class for Catalyst that will simply and efficiently create 'thumbnails' or scaled down versions of images using arguably the most sane perl image manipulation library, Imager. The behavior of this module is controlled by stash and config values.
A scalar reference containing raw image data.
An integer in pixels of the desired longest side of the image. It will be scaled accordingly, maintaining it's original aspect ratio.
You can set this attribute to a string (e.g. 'png') to try to force Imager to write an image of a certain file format (note that this may fail). Otherwise the image type is automatically derived from the source image.
Set this to true to cause the image to be cropped into a square. See crop() in Imager::Transformations. Note that this takes place before the image is scaled (if image_size is available).
An integer in bytes of the largest size of image you want Imager to read (defaults to 15 megabytes). Note that this can also be set in your application's configuration like so:
# example in YAML View::Thumbnail::Simple: max_image_size: 10_485_760
This module will avoid reading in image data unless necessary for scaling, cropping or transcoding (if the stash values are set, original image dimensions are checked as well as type). This is done to avoid unnecessary re-compression and loss of quality. If you want to force this module to read and write the image data regardless of these variables, set this stash key to a true value.
See above section about max_image_size
Pick what Imager scaling algo to use, defaults to 'mixing'. Please see the documentation on 'scale()' in Imager::Transformations.
An integer between 0-100 used to determine the quality of the image when writing JPEG files, defaults to 100. Please see the JPEG section of Imager::Files.
After generating the thumbnail from the image data, the following stash values will be set:
The scaled Imager image object.
A scalar reference containing the raw data of the scaled image (this could be useful for caching purposes).
Imager requires several libraries (e.g. libpng, libjpeg) for the ability to read some image file types. If you are unsure if you have these dependencies installed, type the following in your command shell to reveal what image types your version of Imager can currently read:
perl -MImager -e 'print join(q{, }, Imager->read_types) . qq{\n}'
See the Imager perldocs for more information on image formats.
Copyright (C) 2011 <aesop@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available.
To install Catalyst::View::Thumbnail::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::View::Thumbnail::Simple
CPAN shell
perl -MCPAN -e shell install Catalyst::View::Thumbnail::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.