开发者

Transparency with Python Image Library

I'm trying to place a PNG watermark with partial transparency on top of a Facebook profile pic (jpg) using the Python Image Library. The part that should be transparent simply comes off as white. Here's my code:

con = urllib2.urlopen('facebook_link_to_profile_pic')
im = Image.open(cStringIO.StringIO(con.read()))

overlayCon = urllib2.urlopen('link_to_overlay')
overlay = Image.open(cStringIO.StringIO(overlayCon.read()))

im.paste(overlay, (0, 0))

im.save('name', 'jpeg', quality=100)

I've tried a few different 开发者_开发问答ways, but haven't gotten anything to work. Any help is appreciated.


The 3rd option to paste is a mask (see the docs). It accepts an RGBA image, so the simplest solution is to use your overlay image again: im.paste(overlay, (0, 0), overlay).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜