note 37903 added to function.getimagesize
| From: | php at rn2 dot php dot net | Date: | Mon, 01 Dec 2003 23:39:28 +0000 |
| Subject: | note 37903 added to function.getimagesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-61235@lists.php.net to get a copy of this message | ||
If you want to resize an image proportionally to fit within a given area, like I did, the following
code might help you out.
If either hscale or wscale are greater than 1 then that dimension is too big. If you then scale your
image by the larger of the two values (hscale, wscale) then you guarantee that both dimensions will
now fit in your specified area :)
function makeImg($num) {
global $hmax, $wmax; // max width and height
$image = "somefile.jpg";
list($width, $height, $type, $attr) = getimagesize($image);
$hscale = $height / $hmax;
$wscale = $width / $wmax;
if (($hscale > 1) || ($wscale > 1)) {
$scale = ($hscale > $wscale)?$hscale:$wscale;
} else {
$scale = 1;
}
$newwidth = floor($width / $scale);
$newheight= floor($height / $scale);
return "<img width='$newwidth' height='$newheight'
src='$image'><br>$image: $newwidth x $newheight : $width x $height";
}
----
Manual Page -- http://www.php.net/manual/en/function.getimagesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37903
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37903&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37903&report=yes
Search -- http://master.php.net/manage/user-notes.php