Why does this transparent PNG cause borders when combined using GD?

前端 未结 2 1180
北荒
北荒 2020-12-19 10:09

I am trying to create an image from an another image using PHP. Here is my code:



        
2条回答
  •  余生分开走
    2020-12-19 10:59

    You have partial transparency around the edges of your source image. That makes it combine with the black of the canvas image (which you normally can't see because it's 100% transparent), giving the results you see. You could avoid this by making sure your entire alpha channel on the source image is either 100% or 0%, or by choosing a more appropriate base color for your canvas image (i.e. one that matches the background color scheme of your site).

    Fabio Anselmo's comment would help in that GIFs don't have a real alpha channel -- GIF transparency is all-or-nothing -- so saving as one will accomplish the 100%-or-0% solution. Unless you're extremely careful it will also give you a "border" right there in the source image -- made up of whatever background color you have or select in the GIF conversion -- as a result of your image's antialiasing. (However, the interlacing part is irrelevant.)

提交回复
热议问题