Script CLI instead of PerlMagick
Posted: 2010-06-17T05:09:41-07:00
With ImageMagick convert or mogrify is the option -auto-orient. If your camera has its AutoOrient option turned on, the EXIF file writes the camera's orientation to the shot. ImageMagick manually rotates the image so you have no surprises when posting that image to the web. Otherwise, programs like Photoshop silently rotate a JPEG for >>viewing<<, lets you make changes, SaveAs and when posted to the web, the image is a vertical image laying on its side. -auto-orient is an expensive operation when converting a folder full of JPEG. After much trial-and-error (I had to learn perl), I made this simple script. It uses the Command-Line-Interface in Linux instead of PerlMagick. I used CLI instead of the PerlMagick interface for the following reasons...
1. I need the value of the EXIF:['Orientation']. the code then branches with ... if > 1, do -auto-orient
2. I can get the image specs I want with a compound command in ImageMagick. Here it is:
My goal is best image for SVGA on MS platforms for web and PowerPoint usage. I can gang the ImageMagick options with a CLI. I cannot gang the options with PerlMagick (or can I ? ? ? ?).
3. I needed to capture the value of EXIF:['Orientation'], and as a numeric. I used ExifTool, which is another tool, separate from ImageMack. Here's the perl script...
Putting the above script into a folder, making the directory /converted, CD into the folder and
takes about 55 minutes to make 980 JPG of 5.5meg+, into resampled PNG of 500k on a AMD64, single-core, 3.8mgHz, 2-gig RAM on a USB external drive, Linux OS (Ubuntu 9.10), package-installs of ImageMagick, PerlMagick, ExifTool and their libs.
Can I gang the options in PerlMagick?? I found this is important to resample the dpi I seek, then do the image's new dimensions. I would like to rewrite the script as all PerlMagick, perhaps, to see if I can get even better performance.
1. I need the value of the EXIF:['Orientation']. the code then branches with ... if > 1, do -auto-orient
2. I can get the image specs I want with a compound command in ImageMagick. Here it is:
Code: Select all
$command = "convert -auto-orient -resample 96 -resize \"x640\" -strip $_ converted/$fname.png";
3. I needed to capture the value of EXIF:['Orientation'], and as a numeric. I used ExifTool, which is another tool, separate from ImageMack. Here's the perl script...
Code: Select all
#!/usr/bin/perl -w
use Image::ExifTool qw(:Public);
### [[ http://www.sno.phy.queensu.ca/~phil/exiftool/ExifTool.html ]] ###
while( glob('*.JPG') ) {
my $exifTool = new Image::ExifTool;
my $meta = $exifTool->ImageInfo( $_ ); # required, constructs the ObjectFile:EXIF, or use perl bless()
my $tag = "Orientation";
my $v = $exifTool->GetValue($tag, 'ValueConv'); # reads the exif values, fetches a field, ValueConv as numeric
my $fname = substr( $_, 0, rindex($_, '.') ); # strips the .JPG off the file name
my $command;
if( $v > 1 ) {
$command = "convert -auto-orient -resample 96 -resize \"x640\" -strip $_ converted/$fname.png";
} else {
$command = "convert -resample 96 -resize \"640x\" -strip $_ converted/$fname.png";
}
open IN, "$command |" or die "no run: $!\n";
close IN;
print "converted : $fname\n";
}
Code: Select all
perl exif_magick.pl
Can I gang the options in PerlMagick?? I found this is important to resample the dpi I seek, then do the image's new dimensions. I would like to rewrite the script as all PerlMagick, perhaps, to see if I can get even better performance.