Image::Thumbnail
Image::Thumbnail - Simple thumbnails with various Perl libraries
use Image::Thumbnail 0.65;
# Create a thumbnail from 'test.jpg' as 'test_t.jpg'
# using ImageMagick, Imager, GD or Image::Epeg.
my $t = new Image::Thumbnail(
size => 55,
create => 1,
input => 'test.jpg',
outputpath => 'test_t.jpg',
);
# With Image Magick
my $t = new Image::Thumbnail(
size => "55x75",
create => 1,
module => "Image::Magick",
input => $imageObject,
outputpath => 'test_t.jpg',
);
# Create a thumbnail from 'test.jpg' as 'test_t.jpg'
# using GD.
my $t = new Image::Thumbnail(
module => 'GD',
size => 55,
create => 1,
input => 'test.jpg',
outputpath => 'test_t.jpg',
);
# Create a thumbnail from 'test.jpg' as 'test_t.jpg'
# using Imager.
my $t = new Image::Thumbnail(
module => 'Imager',
size => 55,
create => 1,
input => 'test.jpg',
outputpath => 'test_t.jpg',
);
# Create a thumbnail as 'test_t.jpg' from an ImageMagick object
# using ImageMagick, or GD.
my $t = new Image::Thumbnail(
size => "55x25",
create => 1,
input => $my_image_magick_object,
outputpath => 'test_t.jpg',
);
# Create four more of ever-larger sizes
for (1..4){
$t->{size} = 55+(10*$_);
$t->create;
}
exit;
This module was created to answer the FAQ, 'How do I simply create a
thumbnail with pearl?' (sic). It allows you to easily make thumbnail images
from files, objects or (in most cases) 'blobs', using either the ImageMagick,
Image::Epeg, Imager or GD libraries.
Thumbnails created can either be saved as image files or accessed as objects
via the object field: see /create.
In the experience of the author, thumbnails are created fastest with direct use of the Image::Epeg module.
One of Image::Magick, Imager, Image::Epeg, or GD.
Parameters are supplied as a hash or hash-like list of name/value pairs: See the /SYNOPSIS.
100x120.
You must the input parameter as one of:
module field (see above).
The formerly required input fields should be considered depricated, and although they will be kept in the API for this release, they will eventually be removed.
If you wish to use a specific module, place its name here. You must have the module you require already installed!
Supplying no name will allow ImageMagick, then Imager to be tried before GD.
create method automatically before returning.
If you are using GD, you can explicitly set the input
and output formats for the image file, provided you use
a string that can be evaluated to a GD-supported image
format (see GD).
Default behaviour is to attempt to ascertin the file type
and to create the thumbnail in the same format. If the
type cannot be defined (you are using GD, have supplied
the object field and not the outputtype field) then
the output file format defaults to jpeg.
Sets colour depth in ImageMagick - AFAIK GD only supports 8-bit.
The ImageMagick manpage (see http://www.imagemagick.org/www/ImageMagick.html#opti). says:
96x96.
Set command when the thumbnail is created. Any errors these
may generate are not yet caught.
Put any value in this field for real-time process info.
As of version 0.4, any errors are stored in the fields
error, warnings in warning.
Any errors will be printed to STDOUT. If they completely
prevent processing, they will be fatal (croaked). If
partial processing has taken place by the explicit or implicit
calling of the create method, then the field of the same
name will have value.
Depending on how far processing has proceded, other fields may have useful values:
the module field will contain the name of the module used;
the object field may contain an object of the module used;
the thumb field may contain a thumbnail image.
Creates a thumbnail using the supplied object.
This method is called automatically if you construct with the
create field flagged.
Sets the following fields:
Returns c<undef> on failure.
None.
Please see the file CHANGES included with the distribution.
perl, Image::Epeg, GD, Imager, Image::Magick, Image::Magick::Thumbnail, Image::GD::Thumbnail, Image::Epeg.
Lee Goddard <cpan-at-leegoddard-dot-net>
Thanks to Sam Tregar, Himmy and Chris Laco.
Copyright (C) Lee Godadrd 2001-2005. All rights reserved. Supplied under the same terms as Perl itself.