-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
imagecopyresampled() produce artifacts on transparent PNG #661
Comments
Hi @jskp4 ,
The latest GD version is v2.3.0. There is no v2.5 right now. I think you mean v2.2.5? :) |
To clarify, you're complaining about the dark pixels in the corners of the image, and the "antialising" like effect around the pentagon shape? The latter is how gdImageCopyResampled() is supposed to work (more or less anyways), but the former looks like a bug (it seems that out of canvas pixels are assumed to be black, and taken into consideration). |
Thank you @willson-chen, you're right, i meant version 2.2.5 |
Hi @cmb69, I meant gray lines over a transparent layer, it shouldn't be there. The transparent layer on the input image is white here and yellowed on the output image to make the lines easier to see. |
Regardless of whether there is a bug or the behavior is intended, I suggest to use |
I tried imagescale() with the IMG_NEAREST_NEIGHBOR parameter and it works, but the image quality is much worse than with imagecopyresampled(), as you can see in the attached image. Such deterioration in exchange for removing artifact on the transparent layer is not appropriate. imagecopyresampled() in the previous version worked well, the quality was good and there were no elements on the transparent layer. Something must have changed in this function, maybe it would be enough to change it back. |
We have an increasingly frequent occurrence of this issue as it seems that more and more web hosts start to include GD library 2.2.5 and above in their setups. Here are some examples. GD pre-2.2.5GD 2.2.5
|
Long time sorry |
@chrisdeeming do you have the original image pls? The 2.3.0, is that usuing copyresampled? |
@jskp4 nearest neighbor uses no interpolation at all but the nearest pixel. So the result is expected. |
@jskp4 could you try using the imagescale example please? I tried using the src image you provided and I cannot see the artifacts. Other filters as well. That does not solve imagecopyresampled however that can gives you a better alternative. I also improved slightly the filters earlier, you can try them out today. Results are as accurate than with IM/GM or other references libraries. |
@chrisdeeming I would need the source images please. If you have it. |
Thanks for the reply @pierrejoye, I'm a little busy now, I'll try it in a few days and I'll let you know. |
should do it. I try with image with only transparency (a==127), random values, grids, gradients, etc. With surfaces of the images bigger from 2x2 to 20x20 transparency or partially, rounding to closest channel integer value works again. |
@cmb69 some tests fail now for gdImageCopyResampled, however it is expected as the rounding is now correct (it was changed to truncate instead of an actual roundf). That could bring down the channel values to 1.5-2 levels down on each channel. |
This is a simplified reproduction of the code within our application. It should probably work with any set of images in place of 1-4.jpeg; these were just from lorempixel.com. Results: GD 2.1GD 2.2.5+ |
@chrisdeeming reports a regression in GD 2.2.5, but |
@chrisdeeming thank you! Here is the result with the above fix: I kept the alpha instead of white so it allows me to see if alpha would be affected as well. There is no non full alpha nor non zero rgb in the padding area. It seems that fixes it as well for your usecase. |
@cmb69 distros do custom patches. They must have backported this only now. Also the issues @chrisdeeming are more "visible" due to the JPEG output. The background with alpha is black. JPEG cancels the alpha, so that creates the dark gray points in the padding area. |
But artifacts only appear when the output image is reduced, for example to 225 x 225 px. I don't know if there was a problem with the artifacts with imagescale(), but there was another problem with deteriorating image quality as can be seen in the post #661 (comment) . I use php-gd and I don't know how I can easily try your solution. Can you try it with the picture below, please? Reduce its size through imagescale() to 320 x 320 px. |
imagecopyresampled() produce many artifacts on transparent PNG.
I added a yellow layer to the output image to make the artifacts easier to see.
In the test code below a small resolution (thumbnail) is used on the output image, but similar artifacts also appear in higher resolutions.
Everything worked well on previous GD version (2.0 I think), but after the upgrade on v 2.2.5, the artifacts began to appear.
I was looking for a solution on the internet, but I did not find anything functional, it is probably a bug in the function imagecopyresampled().
Test code:
Input image:
![source](https://user-images.githubusercontent.com/63653424/98987991-45353800-2527-11eb-9b9e-8eebe0247670.png)
Output image:
![imagecopyresample1](https://user-images.githubusercontent.com/63653424/98989335-41a2b080-2529-11eb-8d0f-6c7205f90974.png)
The text was updated successfully, but these errors were encountered: