in reply to jpg file demensions
sub scale_dimentions { my ($width, $height, $max_width, $max_height) = @_; my $width_factor; my $height_factor; my $new_width; my $new_height; my $factor; $width_factor = $max_width / $width; $height_factor = $max_height / $height; if ($width_factor < 1 || $height_factor < 1) { if ($width_factor < $height_factor) { $factor = $width_factor; } else { $factor = $height_factor; } $new_width = int($width * $factor + 0.5); $new_height = int($height * $factor + 0.5); } else { $new_width = $width; $new_height = $height; } return ($new_width, $new_height); } printf("%d,%d$/", scale_dimentions(2272, 1704, 800, 600)); # 800,600 printf("%d,%d$/", scale_dimentions(1704, 2272, 800, 600)); # 450,600 printf("%d,%d$/", scale_dimentions(2272, 1704, 150, 150)); # 150,112 printf("%d,%d$/", scale_dimentions(1704, 2272, 150, 150)); # 112,150
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: jpg file demensions
by kmarshall (Novice) on Nov 22, 2004 at 22:12 UTC | |
by tall_man (Parson) on Nov 22, 2004 at 23:01 UTC |