php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29315 Bug in imagecopyresampled
Submitted: 2004-07-22 09:56 UTC Modified: 2004-11-19 14:22 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: k at ailis dot de Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 4.3.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: k at ailis dot de
New email:
PHP Version: OS:

 

 [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. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-23 09:26 UTC] k at ailis dot de
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) 
}
 [2004-07-27 15:36 UTC] tony2001@php.net
http://tony2004.phpclub.net/dev/tmp/bug.png - is this what you need?
If yes - please, try the next CVS snapshot, it should be fixed now.
 [2004-07-27 15:52 UTC] k at ailis dot de
No. I've downloaded and opened your bug.png with GIMP and 
I still see blue snow around the second line. So the bug 
is still there. 
 
You must use a viewer which can display alpha-transparency 
like GIMP, ImageMagick or a capable browser like Mozilla 
to see the bug.
 [2004-11-19 14:22 UTC] pajoye@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Side effect of the resizing method in imagecopyresampled.

Cannot be "fixed".

ImageCopyResamples is not good for each kind of images but is not that bad for a "all-in-one" usage.

--Pierre
 [2011-04-08 20:08 UTC] vlastimil dot miler at gmail dot com
Not a bug? You must be joking. When given completely transparent image, the result is not completely transparent image. It cannot deal with a simplest of cases correctly.

It may be a limitation of the used algorithm for a gd developer, but it is a bug for the end user.

You can claim that white is just a very bright black, but I still see it as white.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 26 02:05:45 2022 UTC