in reply to jpg file demensions

Once you get the dimentions using Image::Magick or whatever, here's code to maintain proportions:
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
    If I am running a website off of another server, where I do not have access to install new modules, how would I go about do such?

    Thanks
      You could request the service provider to install the module for you (maybe change providers if they won't), or you could get the Image::Size module from CPAN, look at the subroutine "jpegsize", and adapt that code into a subroutine for your script (giving proper credit to the module author of course).