note 81043 added to function.getimagesize
| From: | shmohel at gmail dot com | Date: | Tue, 12 Feb 2008 14:27:35 +0000 |
| Subject: | note 81043 added to function.getimagesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136066@lists.php.net to get a copy of this message | ||
Rather than making a lengthy function that essentially runs twice (once as width, once as height) I
came up with a helpful function that uses variable variables to set a maximum height/width. Hope
someone finds this helpful.
function scaleimage($location, $maxw=NULL, $maxh=NULL){
$img = @getimagesize($location);
if($img){
$w = $img[0];
$h = $img[1];
$dim = array('w','h');
foreach($dim AS $val){
$max = "max{$val}";
if(${$val} > ${$max} && ${$max}){
$alt = ($val == 'w') ? 'h' : 'w';
$ratio = ${$alt} / ${$val};
${$val} = ${$max};
${$alt} = ${$val} * $ratio;
}
}
return("<img src='{$location}' alt='image' width='{$w}'
height='{$h}' />");
}
}
----
Server IP: 64.71.164.2
Probable Submitter: 63.138.244.24
----
Manual Page -- http://www.php.net/manual/en/function.getimagesize.php
Edit -- https://master.php.net/note/edit/81043
Del: integrated -- https://master.php.net/note/delete/81043/integrated
Del: useless -- https://master.php.net/note/delete/81043/useless
Del: bad code -- https://master.php.net/note/delete/81043/bad+code
Del: spam -- https://master.php.net/note/delete/81043/spam
Del: non-english -- https://master.php.net/note/delete/81043/non-english
Del: in docs -- https://master.php.net/note/delete/81043/in+docs
Del: other reasons-- https://master.php.net/note/delete/81043
Reject -- https://master.php.net/note/reject/81043
Search -- https://master.php.net/manage/user-notes.php