Ever wanted to get the size of an image?
Possibly to determine new height and width dimensions that DO NOT distort the proportion.
Well I have, and I overcame the math like so.

First you must decide on an image width. The subroutine returns the proportional height equivalent. It uses the Image::Size module, which is available from CPAN and may be placed in a subfolder on your local server. And linked to from your script via the use lib "./yourfolder"; use Image::Size; command.

It takes to arguments, the fixed width, and the path to the image. (relative OK)


use strict;
use CGI;
use Image::Size; #(if installed to lib) 

my $q = CGI->new();

my $height = &getImgHeight('../img/theImage.jpg', 200);

print $q->img({ -width => '200', height => $height});
sub getImgHeight {
use Image::Size;

my ($w, $h) = imgsize(shift);
my $temp = substr((shift / $w), 0, 5);
(my $height = ($h * $temp)) =~ s/\.+\d*$//;

return $height;

Image-Size has dependencies, so adding it via the lib pragma may not work unless the depenedencies are also added.

It is a good way though to get image dimensions.

The comment I would like deleted is the one that contains the text "Please delete this comment:)". NOT the one from KevinADC.

Moderator?? Help!