Making thumbnails with Perl

With the help of ImageMagick you can automagically use Perl to create thumbnails. The example below is quite rude and makes a 50 by 50 thumbnail (no matter which size and shape the master had). Before using it in a real world scenario, check the aspect ratio, the size of the original image and what ever may be applicable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl -w
use strict;
use Image::Magick;
 
my $image = Image::Magick->new(magick=>'JPEG');
my $x = $image->Read('test.jpg');
 
$x = $image->Scale(width=>'50', height=> '50');
 
# The following should also work fine...
# $x = $image->Scale(geometry=> '50x50');
 
$x = $image->Write('test.50x50.jpg');
 
exit();