Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: determining size of image

by ikegami (Patriarch)
on Feb 22, 2007 at 17:06 UTC ( #601590=note: print w/replies, xml ) Need Help??


in reply to determining size of image

my ($width, $height ) = ...; my ($max_width, $max_height ) = (800, 600); my ($width_factor, $height_factor) = ($max_width/$width, $max_height/$ +height); if ($width_factor < 1 || $height_factor < 1) { my $factor = ($width_factor < $height_factor ? $width_factor : $height_factor ); $width = int($width * $factor + 0.5); $height = int($height * $factor + 0.5); }

The above was extracted from a script I use to resize images.

use Image::Magick qw(); my $img = Image::Magick->new(); my $file_name = ...; my $img->Read($file_name); my ($width, $height ) = $img->Get(qw( width height )); my ($max_width, $max_height ) = (800, 600); my ($width_factor, $height_factor) = ($max_width/$width, $max_height/$ +height); if ($width_factor < 1 || $height_factor < 1) { my $factor = ($width_factor < $height_factor ? $width_factor : $height_factor ); my $new_width = int($width * $factor + 0.5); my $new_height = int($height * $factor + 0.5); $img->Resize(width => $new_width, height => $new_height); $img->Write($file_name); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://601590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2023-02-07 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (39 votes). Check out past polls.

    Notices?