Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch, resize, or thumbnail an image using Perl

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

like image 904
Anil Avatar asked Jan 28 '09 08:01

Anil


2 Answers

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

like image 158
Ranguard Avatar answered Oct 20 '22 00:10

Ranguard


You could use Image::Resize.

like image 44
mac Avatar answered Oct 20 '22 00:10

mac