Python PIL 为图片添加 PNG 透明水印

效果参见:http://blog.ixcv.com/post/360.html

部分代码:

def waterMark(im, wm):
    if im.mode != 'RGBA':
	    im.convert('RGBA')
	layer = Image.new('RGBA', im.size, (0,0,0,0))
	layer.paste(wm, (im.size[0]-wm.size[0]-im.size[0]/20, im.size[1]-wm.size[1]-im.size[1]/10))
	im = Image.composite(layer, im, layer)
	return im
im = Image.open('./picture.jpg')
wm = Image.open('./watermark.png')
newIm = waterMark(im, wm)
newIm.save('./newPicture.jpg')