|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-03 00:23 UTC] seth at pricepages dot org
Description:
------------
I'm not sure how many bugs are hidden here, but I thought
this should be submitted.
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:
tmp = gdImageGetPixel (src, x, y);
if (gdImageGetTransparent (src) == tmp) {
tox += stx[x - srcX];
continue;
}
But if the alpha blending is set to false, you want to copy
the transparent pixels. So commenting out this if statement
removes one bug. There is other similar code in this loop,
so maybe it should all be removed?
Unfortunately, all result pixels still opaque, when the
source image pixels are partially transparent. So this code
does not fix the problem.
Reproduce code:
---------------
<?php
$small = imagecreatefrompng(
'http://pricepages.org/temp/partialTrans.png');
$width = 300;
$height = 300;
$srcW = imagesx($small);
$srcH = imagesy($small);
$img = imagecreatetruecolor($width, $height);
$red = imagecolorresolve($img,255,0,0);
imagefill($img, 0,0, $red);
imagealphablending($img, false);
imagecopyresized($img, $small, 0,0, 0,0, $width, $height, $srcW, $srcH);
header('Content-Type: image/png');
imagepng($img);
?>
Expected result:
----------------
The image is filled with red, and a partially transparent
black-and-white image is composited on top of it. Because
alpha blending is set to false, there should be no red showing
in the final image. (bug#1, squashed above)
Also, because the greyscale image should have partial
transparency, there should be a gradient between black and
red, but there is none. It is only black or only red. (bug#2)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 05:00:01 2025 UTC |
"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?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'); ...