note 52965 added to function.imagecopyresampled
| From: | carnivorous_winds_frATyahooDOTfr at osu1 dot php dot net | Date: | Thu, 19 May 2005 05:47:27 +0000 |
| Subject: | note 52965 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89614@lists.php.net to get a copy of this message | ||
I tried this code from a previous post.
<?
...
$t_im = imageCreateTrueColor($t_wd,$t_ht);
imageAntiAlias($t_im,true);
imagealphablending($t_im, false);
imagesavealpha($t_im,true);
$transparent = imagecolorallocatealpha($t_im, 255, 255, 255, 0);
for($x=0;$x<$t_wd;$x++) {
for($y=0;$y<$t_ht;$y++) {
imageSetPixel( $t_im, $x, $y, $transparent );
}
}
imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
imagePNG($t_im, $image_name);
...
?>
It seems that it is not working correctly. In my test the source picture in ImageCopyResampled() is
smaller than the destination picture $t_im, the remaining part is white !
I changed transparent alpha channel to 127, and I tried to replace loops with
imagefilledrectangle().
It works fine and these resource greedy loops are removed.
Here is the code with my change.
<?
...
$t_im = imageCreateTrueColor($t_wd,$t_ht);
imageAntiAlias($t_im,true);
imagealphablending($t_im, false);
imagesavealpha($t_im,true);
$transparent = imagecolorallocatealpha($t_im, 255, 255, 255, 127);
imagefilledrectangle($t_img, 0, 0, $t_wd, $t_ht, $transparent);
imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
imagePNG($t_im, $image_name);
...
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52965
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52965&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52965&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52965&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52965&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52965&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52965&report=yes
Search -- http://master.php.net/manage/user-notes.php