note 89987 added to function.imagecopyresampled
| From: | zuegs at osu1 dot php dot net | Date: | Wed, 01 Apr 2009 06:52:29 +0000 |
| Subject: | note 89987 added to function.imagecopyresampled | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152681@lists.php.net to get a copy of this message | ||
Resampling GIFs and retain transparency dosen't work always, as dependent on the resample
factor the resulting resampled image has some pattern-noise that prevents "imagegif" to
find all the transparent-pixels.
One way to fix this, is to reset all pixels with high alpha to full-transparent:
<?php
// load/create images
$img_src=imagecreatefromgif($g_srcfile);
$img_dst=imagecreatetruecolor($g_iw,$g_ih);
imagealphablending($img_dst, false);
// get and reallocate transparency-color
$transindex = imagecolortransparent($img_src);
if($transindex >= 0) {
$transcol = imagecolorsforindex($img_src, $transindex);
$transindex = imagecolorallocatealpha($img_dst, $transcol['red'],
$transcol['green'], $transcol['blue'], 127);
imagefill($img_dst, 0, 0, $transindex);
}
// resample
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
// restore transparency
if($transindex >= 0) {
imagecolortransparent($img_dst, $transindex);
for($y=0; $y<$g_ih; ++$y)
for($x=0; $x<$g_iw; ++$x)
if(((imagecolorat($img_dst, $x, $y)>>24) & 0x7F) >= 100) imagesetpixel($img_dst,
$x, $y, $transindex);
// save GIF
imagetruecolortopalette($img_dst, true, 255);
imagesavealpha($img_dst, false);
imagegif($img_dst, $g_dstfile);
imagedestroy($img_dst);
?>
----
Server IP: 194.153.94.10
Probable Submitter: 83.79.86.120
----
Manual Page -- http://www.php.net/manual/en/function.imagecopyresampled.php
Edit -- https://master.php.net/note/edit/89987
Del: integrated -- https://master.php.net/note/delete/89987/integrated
Del: useless -- https://master.php.net/note/delete/89987/useless
Del: bad code -- https://master.php.net/note/delete/89987/bad+code
Del: spam -- https://master.php.net/note/delete/89987/spam
Del: non-english -- https://master.php.net/note/delete/89987/non-english
Del: in docs -- https://master.php.net/note/delete/89987/in+docs
Del: other reasons-- https://master.php.net/note/delete/89987
Reject -- https://master.php.net/note/reject/89987
Search -- https://master.php.net/manage/user-notes.php