ID: 39353 Updated by: [EMAIL PROTECTED] Reported By: seth at pricepages dot org Status: Feedback Bug Type: GD related Operating System: Mac 10.4 PHP Version: 5CVS-2006-11-02 (snap) Assigned To: pajoye New Comment:
Another thing you may not know is how to preserve the alpha channel information on save: http://blog.thepimp.net/misc/bug39353_with_alpha.png you have to use imagesavealpha($img,true); before calling imagepng. Previous Comments: ------------------------------------------------------------------------ [2006-11-04 17:26:18] [EMAIL PROTECTED] "I thought that a color with alpha = 127 will produce the same results as a color marked as transparent. I want the contents of $small to overwrite everything in $img. This is not correct?" But this color (imagecolortransparent($small)) *IS* the transparent color and is ignored on copy. http://blog.thepimp.net/misc/bug39353_out.png is it not what you expect? If not, provide an image to show what you expect. ------------------------------------------------------------------------ [2006-11-04 17:11:55] seth at pricepages dot org Also, if you alter the transparency of a color to be 64, and you fill the image with that color, shouldn't the final image have a transparency of 64? imagecolorsforindex() gives the correct alpha value, but the "true color" PNG produced in my browser has no partial transparency. (it is all opaque) The code that I am using looks like this: ... $img = imagecreatetruecolor($width, $height); $red = imagecolorallocatealpha($img, 255,0,0, 64); imagefill($img, 0,0, $red); imagealphablending($img, false); /* var_dump(imagecolorsforindex($img, imagecolorat($img, 0,0))); exit; //*/ header('Content-Type: image/png'); ... ------------------------------------------------------------------------ [2006-11-04 17:01:40] seth at pricepages dot org I thought that a color with alpha = 127 will produce the same results as a color marked as transparent. I want the contents of $small to overwrite everything in $img. This is not correct? The "bug#1" and "bug#2" that I wrote were not intended to be links, they were just supposed to show that I believe there are two bugs at work here. This web site turned them into links. To reproduce the second bug without changing the first, alter my code to look like this: ... $img = imagecreatetruecolor($width, $height); $red = imagecolorallocate($img, 255,0,0); imagecolortransparent($img, $red); imagefill($img, 0,0, $red); imagecopyresized($img, $small, 0,0, 0,0, $width, $height, $srcW, $srcH); ... The background is supposed to be transparent, but where $small has partial transparency, $img becomes fully opaque. The final image should have partial transparency around the object, but it does not. ------------------------------------------------------------------------ [2006-11-04 15:52:11] [EMAIL PROTECTED] "imagecopyresized() is ignoring alpha the blending mode. Specifically, in ext/gd/libgd/gd.c line 2376 or so, there is this code that skips processing transparent pixels:" My statement covers this part of your report, which is wrong. It is the expected behavior to do not copy the transparent color. The transparent color has nothing to do with the *alpha* channel of any other pixels. The alpha blending mode affects *only* pixels with alpha channels, not the transparent color. Which second bug are you talking about? The link bug#1 and bug#2 does not work, maybe you are refering to them? As a sidenote, it makes no sense to call colorresolve for truecolor images, just use imagecolorallocate or imagecolorallocatealpha. Here is your example, with a check for truecolor or indexed image, and showing which color is the *transparent* color (imagecolortransparent): $small = imagecreatefrompng('bug39353.png'); if (imageistruecolor($small)) { echo "truecolor image\n"; } else { $c = imagecolortransparent($small); echo "transparent index: " . $c . "\n"; print_r( imagecolorsforindex($small,$c)); } $width = 300; $height = 300; $srcW = imagesx($small); $srcH = imagesy($small); $img = imagecreatetruecolor($width, $height); $red = imagecolorallocate($img,255,0,0); imagefill($img, 0,0, $red); imagecopyresized($img, $small, 0,0, 0,0, $width, $height, $srcW,$srcH); imagepng($img, 'a.png'); ?> and the result image: http://blog.thepimp.net/misc/bug39353_out.png Please note that the transparent color is the index 0 and has these values: transparent index: 0 Array ( [red] => 246 [green] => 246 [blue] => 246 [alpha] => 127 ) Is it more clear now? ------------------------------------------------------------------------ [2006-11-04 00:28:54] seth at pricepages dot org Well, you can tell me what I'm doing wrong then. I have a source image with fully transparent pixels. I would like to copy it over another image, so the final image has fully transparent pixels. To do this, I set imagealphablending() to false, and I copy via imagecopyresized(). But no fully transparent pixels are copied. Your statement does not address the second bug that I mentioned. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/39353 -- Edit this bug report at http://bugs.php.net/?id=39353&edit=1