From: k at ailis dot de Operating system: Linux PHP version: 4.3.8 PHP Bug Type: GD related Bug description: Bug in imagecopyresampled
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. -- Edit bug report at http://bugs.php.net/?id=29315&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29315&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29315&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=29315&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=29315&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=29315&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=29315&r=needscript Try newer version: http://bugs.php.net/fix.php?id=29315&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=29315&r=support Expected behavior: http://bugs.php.net/fix.php?id=29315&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=29315&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=29315&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=29315&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29315&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=29315&r=dst IIS Stability: http://bugs.php.net/fix.php?id=29315&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=29315&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=29315&r=float