#!/usr/bin/perl -w

%port = ( 'type' => 'port', 'pda' => '240x320', 'thumb' => '120x160', 'small' => '600x800' );
%land = ( 'type' => 'land', 'pda' => '320x240', '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);
	$suffix="";
	$suffix=".port" if ($width le $height);
	for $sz ("pda") {
		$out = $file;
		$out =~ s/.jpeg/.$sz$suffix.jpeg/;
		$cmd = "convert -size $size{$sz} -resize $size{$sz} $file $out";
		system $cmd;
	}
}
