rescale( 1000, 1234 ); rescale( 100, 1000 ); sub rescale { my ( $height, $width ) = @_; my $maxh = "600"; my $maxw = "800"; if ($height > $maxh || $width > $maxw) { my $hratio = $height / $maxh; my $wratio = $width / $maxw; my $ratio = $hratio > $wratio ? $hratio : $wratio; my $newh = $height / $ratio; my $neww = $width / $ratio; printf "H=%d W=%d ratios: old=%0.2f new =%0.2f\n", $newh, $neww, $height / $width, $newh / $neww; } }