Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: HTML image resizing with Image::Info based on max height/width

by sulfericacid (Deacon)
on Jun 12, 2007 at 01:05 UTC ( #620605=note: print w/ replies, xml ) Need Help??


in reply to HTML image resizing with Image::Info based on max height/width

Can someone see if this would work?

#!/usr/bin/perl use warnings; use strict; my $height = "1000"; my $width = "1234"; my $maxh = "600"; my $maxw = "800"; if ($height > $maxh || $width > $maxw) { my $hratio = $height / $maxh; my $wratio = $width / $maxw; my $newh = $height / $hratio; my $neww = $width / $hratio; print "Height is now $newh, Width is now $neww"; }


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid


Comment on Re: HTML image resizing with Image::Info based on max height/width
Download Code
Re^2: HTML image resizing with Image::Info based on max height/width
by almut (Canon) on Jun 12, 2007 at 02:43 UTC

    It's not quite as trivial as it might seem at first (most of us who have tried probably got it wrong the first time :)

    Just as an example, take a width of 1000 and a height of 100. Your algorithm would compute 6000x600 (W x H), although the expected result would be 800x80 (i.e. max width doesn't exceed 800 and aspect ratio stays at 10:1)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-07-14 06:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (255 votes), past polls