PHP GD resizing transparent image giving black border

前端 未结 1 1414
栀梦
栀梦 2021-02-14 10:27

I am trying to downsize some transparents images in PHP with GD, and whenever I do, there is a weird black-ish border that is added around it.

Before

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 10:52

    I think the problem here is your source image.

    What you have is not a true-color PNG with alpha channel, but an indexed-color PNG with a transparent color. This is apparent if you open the image in Photoshop:

    Image as seen in Photoshop

    This image was created with anti-aliasing already (which gives the yellow text that white-ish border seen here), but when you re-size it, the sub-pixel calculations may go outside of their borders a bit.

    I suspect if you fix the image, making it full RGB with an alpha channel, you won't have this problem.

    0 讨论(0)
提交回复
热议问题