Jpg resize and re-orientation

Here is a perl script for JPG image resizing, and re-orientation according to EXIF:

#!/usr/bin/perl
use Getopt::Std;
use Image::Imlib2;
use Image::EXIF;

$usage="Usage: $0 [-s long-edge-size] input.jpg output.jpg \n";

getopts("hs:");
die $usage if $opt_h;
$long=(defined($opt_s))?$opt_s:1280;

$infile=shift or die $usage;
$outfile=shift or die $usage;

$ori=0;
$exif= new Image::EXIF($infile);
if(!$exif->error){
  $imageinfo=$exif->get_image_info();
  $ori=$imageinfo->{'Image Orientation'};
  if($ori=~/^.*top.*left/i){
    $rot=0;
  }elsif($ori=~/^.*right.*top/i){
    $rot=1;
  }elsif($ori=~/^.*bottem.*right/i){
    $rot=2;
  }elsif($ori=~/^.*left.*bottom/i){
    $rot=3;
  }
}

my $src=Image::Imlib2->load($infile);

if($src->width>$src->height){
  $tg=$src->create_scaled_image($long,0);
}else{
  $tg=$src->create_scaled_image(0,$long);
}
if($rot>0){
  $tg->image_orientate($rot);
}

$tg->save($outfile);

This entry was posted in perl. Bookmark the permalink.

2 Responses to Jpg resize and re-orientation

  1. bet365 says:

    hi I was luck to search your Topics in baidu
    your Topics is excellent
    I learn much in your Topics really thank your very much
    btw the theme of you blog is really impressive
    where can find it

    • huyouncic says:

      For the theme, I simply chose one I like from whatever WordPress provided. I think this one is named “Twenty Ten by the WordPress team”. I think I changed the background.

Leave a comment