Suppose you’ve just filled you digital camera with an endless stream of photos. You want to place them online at your website, but placing 5+ megapixel files online, well…probably a bad idea. Let’s resize them to a propper size – and why not use Perl and ImageMagick for the job. Not a problem, here’s a complete example on how to resize all images in a directory . Make sure you have ImageMagick installed.
Changing files from one format to another is quite easy with a little bit of ImageMagick . In the example below a JPG image (test.jpg) is converted into a GIF-image (test.gif). To output in a different (ImageMagick supported ) format, just change the “image->Set” line.
my $image = Image::Magick->new();
# To explicitly set image format use this instead:
# my $image = Image::Magick->new(magick=> ‘JPEG’);
my $x = $image->Read(‘test.jpg’);
$x = $image->Set(magick => ‘GIF’);
$x = $image->Write(‘test.gif’);