Image::Resize - Simple image resizer using GD
use Image::Resize; $image = Image::Resize->new('large.jpg'); $gd = $image->resize(250, 250);
Resizes images using GD graphics library
Despite its heavy weight, I've always used Image::Magick for creating image thumbnails. I know it can be done using lighter-weight GD, I just never liked its syntax. Really, who wants to remember the lengthy arguments list of copyResized() or copyResampled() functions:
$image->copyResampled($sourceImage,$dstX,$dstY, $srcX,$srcY,$destW,$destH,$srcW,$srcH);
when Image::Magick lets me say:
$image->Scale(-geometry=>'250x250');
Image::Resize is one of my attempts to make image resizing easier, more intuitive using GD.
Constructor method. Creates and returns Image::Resize object. Can accept either GD::Image object, or file system path leading to the image. All the file formats that are supported by GD are accepted.
Returns a GD::Image object for the new, resized image. Original image is not modified. This lets you create multiple thumbnails of an image using the same Image::Resize object.
First two arguments are required, which define new image dimensions. By default resize() retains image proportions while resizing. This is always what you expect to happen. In case you don't care about retaining image proportions, pass 0 as the third argument to resize().
resize()
0
Following example creates a 120x120 thumbnail of a "large" image, and stores it in disk:
$image = Image::Resize->new("large.jpg"); $gd = $image->resize(120, 120); open(FH, '>thumbnail.jpg'); print FH $gd->jpeg(); close(FH);
Returns internal GD::Image object for the original image (the one passed to Image::Resize->new).
Returns original image's width and height respectively. If you want to get resized image's dimensions, call width() and height() methods on the returned GD::Image object, like so:
$gd = $image->resize(120, 120); printf("Width: %s, Height: %s\n", $gd->width, $height);
Thanks to Paul Allen <paul.l.allen AT comcast.net> for the trueColor(1) tip. Now Image::Resize should work fine for photographs too.
trueColor(1)
Thanks to Nicholas Venturella <nick2588 AT gmail.com> for allowing Image::Resize to work with already-opened GD::Image objects and for checking the scaling routine. It's now comparable to Image::Magick's Scale(): the resulting image dimensions won't exceed the given width and height.
Scale()
GD, Image::Magick
Sherzod B. Ruzmetov, <sherzodr@cpan.org> http://author.handalak.com/
Copyright 2005 by Sherzod B. Ruzmetov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Image::Resize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Image::Resize
CPAN shell
perl -MCPAN -e shell install Image::Resize
For more information on module installation, please visit the detailed CPAN module installation guide.