#!/usr/bin/perl -w

%port = ( 'type' => 'port', 'thumb' => '120x160', 'small' => '600x800' );
%land = ( 'type' => 'land', 'thumb' => '160x120', 'small' => '800x600' );

$identify = 'identify -format "%w %h "';

foreach $file (@ARGV) {
	($width, $height) = split (' ', `$identify $file 2>/dev/null`);
	print "$file: $width $height\n";
	next if ($width eq "" || $height eq "");
	%size = %port;
	%size = %land if ($width ge $height);
	for $sz ("thumb", "small") {
		$out = $file;
		$out =~ s/.jpeg/.$sz.jpeg/;
		$cmd = "convert -size $size{$sz} -resize $size{$sz} $file $out";
		system $cmd;
	}
}
