While messing with photos, I needed a simple way to rotate an image that didn’t involve loading up Gimp or Paint Shop, or whatever. Here it is.
What I don’t get is that it segfaults every time I run it. However, the image is always created correctly. Any tips would be welcome. Meanwhile, I’m rotating images with less pain.
Usage: rotateimage img deg where
img is the path to the image, and
deg is the number of degrees through which you want to rotate it, with the default being 90 counterclockwise.
#!/usr/bin/perl use Image::Magick; my $image = Image::Magick->new; my $deg = $ARGV || 90; print "Reading $ARGVn"; open (IMAGE, $ARGV); $image->Read(file=>*IMAGE); close(IMAGE); $image->Rotate($deg); $filename = $ARGV; $filename =~ s/(.*).(.*)$/$1.new.$2/; print "Writing $filenamen"; open(IMAGE, ">$filename"); $image->Write(file=>*IMAGE, $filename=>$filename); close(IMAGE);