开发者

Use a color to create an alpha channel for a PNG?

I have several images that claim to have a transparent background but are actually white. I'd like to use Python Image Library/PIL to set that white background color to actually be transparent.

Since PNG uses an alpha channel, I'd love to create the alpha channel by finding contiguous areas of white开发者_JAVA百科 from the edges of the image (so I don't get "holes" of transparency when the image contains white data).

Any tips on how to create the alpha channel this way?


I'd guess you'd want to run across the image in a spiral from the outside, setting a pixel to transparent if it is white, and a pixel further towards the edge is also white transparent. Stop once you've done a whole circle without changing any pixels.

Shouldn't be too difficult to write such a loop.

Do some kind of flood fill, seeded from the white edge pixels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜