Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: determining size of image

by ikegami (Patriarch)
on Feb 22, 2007 at 17:06 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found