in reply to HTML image resizing with Image::Info based on max height/width
The following snippet is taken from Generate thumbnail and small overstruck images for web publication. $thumbX, $thumbY are the desired dimensions. The $portrait stuff allows the rectangle to be rotated to generate a landscape or portrait image depending on the aspect ratio of the original image. You probably want to omit that for your purposes.
my ($height, $width) = $image->Get ('height', 'width'); my $portrait = $height > $width; my ($x, $y) = ! $portrait ? ($thumbX, $thumbY) : ($thumbY, $thumbX); my $scaleX = $x / $width; my $scaleY = $y / $height; my $scale = $scaleX < $scaleY ? $scaleX : $scaleY; $thumb->Resize (width=>$width * $scale+0.5, height=>$height * $scale ++0.5);
|
|---|