note 50019 added to function.imagecopyresized
| From: | smelbanatsmwebdesignsdotcom at osu1 dot php dot net | Date: | Tue, 15 Feb 2005 16:37:58 +0000 |
| Subject: | note 50019 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85076@lists.php.net to get a copy of this message | ||
Resize image proportionaly where you give a max width or max height
<?php
header('Content-type: image/jpeg');
//$myimage = resizeImage('filename', 'newwidthmax', 'newheightmax');
$myimage = resizeImage('test.jpg', '150', '120');
print $myimage;
function resizeImage($filename, $newwidth, $newheight){
list($width, $height) = getimagesize($filename);
if($width > $height && $newheight < $height){
$newheight = $height / ($width / $newwidth);
} else if ($width < $height && $newwidth < $width) {
$newwidth = $width / ($height / $newheight);
} else {
$newwidth = $width;
$newheight = $height;
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagejpeg($thumb);
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50019
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50019&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50019&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50019&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50019&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50019&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50019&report=yes
Search -- http://master.php.net/manage/user-notes.php