Provides a few basic image management tools for the ExSite CMS. This is just a simple wrapper/API to whatever underlying image processing tools are going to do the heavy lifting, so it is easy to replace or extend with more powerful tools if needed.
This version tries to use Image::Info for fetching image attributes, and the convert shell command for modifying the image itself.
To start working with a new image:
my $img = new ExSite::Image($name,$rawdata); # OR my $img = new ExSite::Image($encoded_data);
To get the image attributes:
my $info = $img->info; # $info is a hash ref
To get the image size:
my ($x,$y) = $img->dim;
To change the image size:
my $stat = $img->scale(500,500,$flag);
# $flag > 0 scale up to that size, if smaller # $flag == 0 scale to that size # $flag < 0 scale down to that size, if larger # retain aspect ratio in all cases
To scale the image to exactly the passed dimensions (the edges may get cropped to achieve the new aspect ratio without stretching the original image):
my $imgdata = $img->scale_crop($x,$y);
# $x: image width # $y: image height
To thumbnail an image (preserve aspect ratio):
my $stat = $img->thumb; # equivalent to $img->scale(100,100,-1);
To get a square thumbnail (some cropping may be involved):
my $imgdata = $img->square_thumb($x);
# $x: image width
To get image raw data:
my $imgdata = $img->get;
To get image data in exsite binary file encoding format:
my $imgdata = $img->encode;