ID: 40572 Updated by: [EMAIL PROTECTED] Reported By: seth at pricepages dot org -Status: Open +Status: Assigned Bug Type: GD related Operating System: Mac 10.4 PHP Version: 5.2.1 Assigned To: pajoye New Comment:
Yes, it will work the same way in php as in 2.0.34. But you can already have the same result by disabling the alpha blending: $img = imagecreatetruecolor(100, 100); imagealphablending($img, false); // <<< Here $trans = imagecolorresolvealpha($img,255,0,0, 127); imagefill($img, 0,0, $trans); $pTrans = imagecolorresolvealpha($img, 0,0,0, 64); imagefilledrectangle($img, 10, 10, 50, 50, $pTrans); imagesavealpha($img,true); imagepng($img); Previous Comments: ------------------------------------------------------------------------ [2007-02-23 00:38:10] seth at pricepages dot org Well, I ran the following code against the newly released C library, and things seem to work as expected. GD 2.0.33 seg faults for some reason, but 2.0.34 fixes that. So, the bug will be fixed when you sync with PHP's code? gdImagePtr img; int trans, pTrans; FILE *fp; img = gdImageCreateTrueColor(100, 100); gdImageAlphaBlending(img, 1); trans = gdImageColorResolveAlpha(img,255,0,0, 127); gdImageFill(img, 0,0, trans); pTrans = gdImageColorResolveAlpha(img, 0,0,0, 64); gdImageFilledRectangle(img, 10, 10, 50, 50, pTrans); gdImageAlphaBlending(img, 0); gdImageSaveAlpha(img,1); fp = fopen("test.png", "w"); gdImagePng(img, fp); fclose(fp); gdImageDestroy(img); ------------------------------------------------------------------------ [2007-02-21 10:03:06] [EMAIL PROTECTED] imagefill does not care about alpha blending but when you use a tiled color (as it is actually an image/pattern filling). "$trans = imagecolorresolvealpha($img,255,0,0, 127);" Will always fill the area with red and a 100% transparent alpha. "imagealphablending($img, true);" enables the blending mode. Set it to false will store the alpha in the image. You set it to true, that's why you get a "red/black" rectangle instead of a gray semi transparent area. However I agree that the behavior is not user friendly. The GD 2.0.34 behaves differently in a more logic way when the dst pixel is either fully transparent or opaque. OS X Fink already have 2.0.34, you can try to compile php against it. Or you can see the different implementation in the GD sources (function gdAlphaBlend): http://cvs.php.net/viewvc.cgi/gd/libgd/gd.c I will try to sync php gdAlphaBlend as soon as possible. I have to check that it will not break BC in one way or another (I do not think it will, but still need to test). Do you get what you expect using the 2.0.34's gdAlphaBlend? ------------------------------------------------------------------------ [2007-02-21 05:01:04] seth at pricepages dot org Description: ------------ I am filling the background of an image with a transparent red (it shouldn't have an effect on the rest of the drawing). Over it, I'm drawing a black, semi-transparent, square. Reproduce code: --------------- $img = imagecreatetruecolor(100, 100); imagealphablending($img, true); $trans = imagecolorresolvealpha($img,255,0,0, 127); imagefill($img, 0,0, $trans); $pTrans = imagecolorresolvealpha($img, 0,0,0, 64); imagefilledrectangle($img, 10, 10, 50, 50, $pTrans); imagealphablending($img, false); imagesavealpha($img,true); header('Content-Type: image/png'); imagepng($img); Expected result: ---------------- I would expect the resulting image to be 100% transparent, except for a grey, 50% transparent square. Actual result: -------------- Instead, the black is mixed with the red to form a dark-red semi-transparent square. The red color should not be there, because it was 100% transparent. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40572&edit=1