|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-07-22 09:56 UTC] k at ailis dot de
Description:
------------
Hello,
I've also send this bug to Boutell (because it is a bug in
the GD library, not in PHP) but I have the feeling that
I'll not get an answer because of the message I got after
submitting the bug.. So maybe someone is able to fix this
bug in the GD library which is bundled with PHP.
There seems to be a bug in gdImageCopyResampled which is
triggered if an alphatransparent image is resampled. The
bug can be reproduced with GD 2.0.28 (and also with the
library bundled with PHP 4.3.8) with the code at the
bottom of this message (It's a C source. I'm putting a PHP
source into the "reproduce code" box)
This example code sets the background color of the
resulting image to transparent so it's easier to see the
bug. Resampling an alpha-transparent image to a
"binary-even" size (2^x, for example: 64x64) works fine,
but other values (like 127x127 in this example) creates
alpha transparent artifacts. Depending on the destination
size of the resampling the artifacts are very different.
To see these artifacts just compile the following code and
start it. You will end up with an out.png which has two
lines in it. The first one is correct (was resized to
64x64), the second one (resized to 127x127) has snow
around the line (only visible if you display the image
with a viewer supporting PNG transparency)
#include <gd.h>
int main(int argc, char *argv[])
{
gdImagePtr alpha_image, test_image;
FILE *file;
int transparent, black, blue;
// Create an alpha-transparent image with a black line
in it
alpha_image = gdImageCreateTrueColor(128, 128);
gdImageAlphaBlending(alpha_image, 0);
gdImageSaveAlpha(alpha_image, 1);
transparent = gdImageColorAllocateAlpha(alpha_image,
0, 0, 0, 127);
black = gdImageColorAllocate(alpha_image, 0, 0, 0);
gdImageFilledRectangle(alpha_image, 0, 0, 128, 128,
transparent);
gdImageLine(alpha_image, 0, 0, 128, 128, black);
// Create a test background image
test_image = gdImageCreateTrueColor(256, 256);
blue = gdImageColorAllocate(test_image, 0, 0, 256);
gdImageColorTransparent(test_image, blue);
gdImageFilledRectangle(test_image, 0, 0, 256, 256,
blue);
// Resample the alpha-transparent image onto the test
image (working)
gdImageCopyResampled(test_image, alpha_image, 10, 10,
0, 0,
64, 64, 128, 128);
// Resample the alpha-transparent image onto the test
image (not working)
gdImageCopyResampled(test_image, alpha_image, 100,
100, 0, 0,
127, 127, 128, 128);
file = fopen("out.png", "w");
gdImagePng(test_image, file);
fclose(file);
return 0;
}
Reproduce code:
---------------
// Create an alpha-transparent image with a sample line in it
$alpha_image = imagecreatetruecolor(128, 128);
imagealphablending($alpha_image, false);
imagesavealpha($alpha_image, true);
$transparent = imagecolorallocatealpha($alpha_image, 0, 0, 0, 127);
$black = imagecolorallocate($alpha_image, 0, 0, 0);
imagefilledrectangle($alpha_image, 0, 0, 128, 128, $transparent);
imageline($alpha_image, 0, 0, 128, 128, $black);
// Create a test background image
$test_image = imagecreatetruecolor(256, 256);
$blue = imagecolorallocate($test_image, 0, 0, 255);
imagecolortransparent($test_image, $blue);
imagefilledrectangle($test_image, 0, 0, 256, 256, $blue);
// Resample the alpha transparent image onto the test image (working)
imagecopyresampled($test_image, $alpha_image, 10, 10, 0, 0,
64, 64, 128, 128);
// Resample the alpha transparent image onto the test image (not working)
imagecopyresampled($test_image, $alpha_image, 100, 100, 0, 0,
127, 127, 128, 128);
// Output image
header('Content-type: image/png');
imagepng($test_image);
Expected result:
----------------
Both lines should be drawn without alpha-transparent
artifacts around them.
Actual result:
--------------
The second line has snow (alpha-transparent artifacts)
around it.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
I've installed this snapshot, The bug is still present. Here is the output of gd_info(): array(11) { ["GD Version"]=> string(27) "bundled (2.0.28 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(true) }