I wanted to quickly resize a collection of images from my Canon IXY200 digital camera. Manually resizing images by running them through an image program like Gimp is a time consuming process. Luckily most versions of Linux have a command line image processor called ImageMagik. In particular, the ImageMagik command: convert -geometry ‘400×300>’ img1 img2 will scale an image so that it fits within 400×300 pixels.
In order to convert multiple photos in one go I wrote the Perl script below:
#! /usr/bin/perl -w
# Perl script to automatically resize Canon IXY200 images to 400x300
# using ImageMagik.
# Note that I had 111 photos. Change to suit your own needs.
for ($i = 1;$i <= 111; $i++)
{
$firstnum = "100";
if ($i < 10)
{
$zeroes = "00";
}
elsif ($i < 100 && $i >= 10)
{
$zeroes = "0";
}
elsif ($i == 100)
{
$zeroes = "";
}
else
{
$zeroes = "";
$firstnum = "101";
}
$file1 = $firstnum."-0".$zeroes.$i."_IMG.JPG";
$file2 = $firstnum."-0".$zeroes.$i."_IMG_400x300.JPG";
system("convert -geometry '400x300>' ".$file1." ".$file2);
print $file1."t".$file2."n";
}
I know that there is a Perl library to access ImageMagik functions. Still this hack of a script did the job, so I can’t complain.