Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Resize image width & height...

by oakbox (Chaplain)
on Jun 28, 2003 at 15:35 UTC ( #269882=note: print w/replies, xml ) Need Help??


in reply to Resize image width & height...

I wrote this for an online image gallery. I wanted the 'long' dimension to be no larger than 450 pixels, so my script needed to do the resizing before commiting the file to disk and I needed to write down the height and width attributes so that I could modify the HTML to display the image correctly. Here's my code:

# write the file to a temporary location my $tmp_loc = $TEMP_IMG_DIR . $image_name; my $whan; open($whan,">$tmp_loc") || die "Cannot write $tmp_loc $!"; print $whan $temp_file_var; close($whan); # Resize image and write it to the appropriate location use Image::Thumbnail; my $t = new Image::Thumbnail( size => 450, create => 1, inputpath => $tmp_loc, outputpath => $main_loc ); # Get the new size of the main image use Image::Info qw(image_info dim); my $info = image_info($main_loc); my ($w, $h) = dim($info);
$temp_file_var is holding the image.
At the end, the new image is written to the path in $main_loc and I have the width $w and the height $h of the new image.

I hope that you can modify this for your use!

oakbox

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-03-31 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (180 votes). Check out past polls.

    Notices?