Rotating an Image with Perl

Turning images is quite simple. In the example below an image is turned 90 degrees clockwise, wirtten to a file, turned another 90 degress and written to a file again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl -w
use strict;
use Image::Magick;
 
my $image = Image::Magick->new(magick=>'JPEG');
my $x = $image->Read('test.jpg');
 
$x = $image->Rotate(degrees=>90); # 90 degress clockwise
$x = $image->Write('test.90.jpg');
 
$x = $image->Rotate(degrees=>90); # Another 90 degress clockwise
$x = $image->Write('test.180.jpg');
 
exit();