#! /usr/bin/perl use warnings; use strict; use Image::Info qw(image_info); use IO::Dir; use Getopt::Std; my $config = {}; ($config->{program_name}) = $0 =~/([^\/]+)\s*$/; if ($#ARGV < 0) { print STDERR "No Directory Specified\nUsage: $config->{program_name} \n"; exit 1; } $config->{dir} ||= $ARGV[0]; my $current_directory = new IO::Dir $config->{dir} or die "Unable to read directory $config->{dir}"; while (defined($_ = $current_directory->read)) { chomp; next unless /(jpg|gif|jpeg|png|pict|bmp)$/i; next unless -f $_; my $image_info = image_info($_); next if not defined $image_info; if ($image_info->{Orientation} eq 'left_bot') { qx(mogrify -rotate -90 $_); } elsif ($image_info->{Orientation} eq 'top_left') { qx(mogrify -noop $_); } elsif ($image_info->{Orientation} eq 'right_top') { qx(mogrify -rotate 90 $_); } elsif ($image_info->{Orientation} eq 'right_bot') { qx(mogrify -rotate 180 $_); } else { qx(mogrify -noop $_); } }