note 61962 added to function.imagecopyresized
| From: | konteinerisatyahoodotcom at osu1 dot php dot net | Date: | Thu, 16 Feb 2006 02:42:07 +0000 |
| Subject: | note 61962 added to function.imagecopyresized | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103824@lists.php.net to get a copy of this message | ||
Function creates a thumbnail from the source image, resizes it so that it fits the desired thumb
width and height or fills it grabbing maximum image part and resizing it, and lastly writes it to
destination
<?
function thumb($filename, $destination, $th_width, $th_height, $forcefill)
{
list($width, $height) = getimagesize($filename);
$source = imagecreatefromjpeg($filename);
if($width > $th_width || $height > $th_height){
$a = $th_width/$th_height;
$b = $width/$height;
if(($a > $b)^$forcefill)
{
$src_rect_width = $a * $height;
$src_rect_height = $height;
if(!$forcefill)
{
$src_rect_width = $width;
$th_width = $th_height/$height*$width;
}
}
else
{
$src_rect_height = $width/$a;
$src_rect_width = $width;
if(!$forcefill)
{
$src_rect_height = $height;
$th_height = $th_width/$width*$height;
}
}
$src_rect_xoffset = ($width - $src_rect_width)/2*intval($forcefill);
$src_rect_yoffset = ($height - $src_rect_height)/2*intval($forcefill);
$thumb = imagecreatetruecolor($th_width, $th_height);
imagecopyresized($thumb, $source, 0, 0, $src_rect_xoffset, $src_rect_yoffset, $th_width,
$th_height, $src_rect_width, $src_rect_height);
imagejpeg($thumb,$destination);
}
}
?>
----
Server IP: 193.219.81.76
Probable Submitter: 85.206.49.97
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresized.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61962
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61962&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61962&report=yes
Search -- http://master.php.net/manage/user-notes.php