#!/perl -w
# NAME: imgratio.pl 
# AIM: Just to re-size an image, keeping the aspect ratio ...
# 17/08/2007 - geoff mclane - geoffiar.net/mperl/samples
use strict;
use warnings;

#my $width = 1134;
#my $height = 751;
#my $width = 1701;
#my $height = 2179;
my $width = 707;
my $height = 519;

my $ratio = $width / $height;

my $twid = 100;
my $imgSx = 0;
my $imgSy = 0;

if($ratio > 1) {
	$imgSx = $twid;
	$imgSy = int( ($twid / $ratio) + 0.5 );
} else {
	$imgSx = int( ($twid * $ratio) + 0.5 );
	$imgSy = $twid;
}

print "From $width x $height, ratio $ratio, gives $imgSx x $imgSy ...\n";

# use HEIGHT
$imgSx = int( ($twid * $ratio) + 0.5 );
$imgSy = $twid;
print "Using HEIGHT: $width x $height, ratio $ratio, gives $imgSx x $imgSy ...\n";

# use WIDTH
$imgSx = $twid;
$imgSy = int( ($twid / $ratio) + 0.5 );
print "Using WIDTH: $width x $height, ratio $ratio, gives $imgSx x $imgSy ...\n";


# eof - imgration.pl
