Question

How can I stretch or resize an image (of any format) using a Perl script?

Was it helpful?

Solution

I'd recommend Image::Imlib2... if you can install imlib2 on your machine

See documentation: Image::Imlib2

use Image::Imlib2;

# load image from file
my $image = Image::Imlib2->load("in.png");

# get some info if you want
my $width  = $image->width;
my $height = $image->height;

# scale the image down to $x and $y
# you can set $x or $y to zero and it will maintain aspect ratio
my $image2 = $image->create_scaled_image($x,$y);

# save thumbnail to file
$image2->save("out.png");

You might also be interested in Image::Imlib2::Thumbnail, if you can not install imlib2 have a look at Image::Magick

OTHER TIPS

You could use Image::Resize.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top