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)
.
精彩评论