note 66054 added to function.imagecopyresampled
| From: | spencejames2000 at yahoo dot co dot uk | Date: | Sat, 13 May 2006 13:27:14 +0000 |
| Subject: | note 66054 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111215@lists.php.net to get a copy of this message | ||
For anyone suffering from the srcX and srcY bug (some versions of gd ignore them completely - see http://bugs.php.net/bug.php?id=12780 for details), a
quick solution is to use this code snippet:
<?php
function imgcopyresampled(&$dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h,
$src_w, $src_h)
{
$tmp_img = imagecreatetruecolor($src_w, $src_h);
$rv2 = imagecopy($tmp_img, $src_img, 0,0, $src_x, $src_y, $src_w, $src_h);
$rv1 = imagecopyresampled($dst_img, $tmp_img, $dst_x,$dst_y, 0,0, $dst_w, $dst_h, $src_w, $src_h);
imagedestroy($tmp_img);
return($rv1 and $rv2);
}
?>
By using imagecopy to extract the relevant portion of the source image, it works a lot more quickly
than pike's solution below, and also without the extra blur.
It may be useful to use override_function in existing projects, although I have not tested this
myself.
----
Server IP: 195.221.21.36
Probable Submitter: 83.157.38.138
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- http://master.php.net/note/edit/66054
Del: integrated -- http://master.php.net/note/delete/66054/integrated
Del: useless -- http://master.php.net/note/delete/66054/useless
Del: bad code -- http://master.php.net/note/delete/66054/bad+code
Del: spam -- http://master.php.net/note/delete/66054/spam
Del: non-english -- http://master.php.net/note/delete/66054/non-english
Del: in docs -- http://master.php.net/note/delete/66054/in+docs
Del: other reasons-- http://master.php.net/note/delete/66054
Reject -- http://master.php.net/note/reject/66054
Search -- http://master.php.net/manage/user-notes.php