note 32543 added to function.getimagesize
| From: | webmaster at rack1 dot php dot net | Date: | Fri, 30 May 2003 22:16:44 +0000 |
| Subject: | note 32543 added to function.getimagesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49444@lists.php.net to get a copy of this message | ||
I figured others have wanted to scale an image to a particular height or width while preserving the
height/width ratio. So here are the functions I wrote to accomplish this. Hopefully they'll
save somebody else the five minutes it took to write these.
You give the filename and the dimension you want to use, and these functions return the opposite
dimension:
function scale_to_height ($filename, $targetheight) {
$size = getimagesize($filename);
$targetwidth = $targetheight * ($size[0] / $size[1]);
return $targetwidth;
}
function scale_to_width ($filename, $targetwidth) {
$size = getimagesize($filename);
$targetheight = $targetwidth * ($size[1] / $size[0]);
return $targetheight;
}
----
Manual Page -- http://www.php.net/manual/en/function.getimagesize.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32543
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32543&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32543&report=yes