8

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

woz
  • 10,888
  • 3
  • 34
  • 64
Anil
  • 3,912
  • 5
  • 35
  • 46
  • 2
    You might want to Google questions like that. – mac Jan 28 '09 at 08:34
  • 4
    You might want to Google any question on stackoverflow. But you may also ask it here. – innaM Jan 28 '09 at 10:26
  • 2
    Google does not help much here, because there are too many solutions available and it is hard to find a really good one. I am so glad this questions was asked. Because until now I always used Image::Resize with GD and it was always a mess (for me). Image::Imlib2 fits my needs much better! – Boris Däppen Nov 08 '12 at 15:22

2 Answers2

8

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

Boris Däppen
  • 1,186
  • 7
  • 20
Ranguard
  • 2,756
  • 3
  • 20
  • 15
3

You could use Image::Resize.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
mac
  • 9,885
  • 4
  • 36
  • 51
  • yeah .. cool and simple. :) I didn't want to give that one because some people might not have/want to install the library hehe – Ric Tokyo Jan 28 '09 at 08:40
  • If you use GD anyway it is a nice interface. If you need to additionally install GD just to make some thumbnails I would not recommend it. I had several problems installing GD on new versions... and this broke my code. – Boris Däppen Nov 08 '12 at 21:48