Creating watermark with transparency on jpeg using PIL?

Max Erickson maxerickson at gmail.com
Sat Aug 20 10:02:06 EDT 2005


You need to pass a mask in when you paste in the watermark.

see the documentation for the paste method at
http://effbot.org/imagingbook/image.htm
for more information

This should at least get you started...

>>> import Image
>>> import ImageDraw
>>> import ImageFont
>>> import ImageEnhance
>>> im=Image.new('RGB',(300,300),(0,0,0))
>>> font=ImageFont.truetype('verdana.ttf',12)
>>> wm=Image.new('RGBA',(100,50),(255,255,255))
>>> im=Image.new('RGB',(300,300),(255,255,255))
>>> draw=ImageDraw.Draw(wm)
>>> draw.text((0,0),'Watermark',(0,0,0),font)
>>> wm.show()
>>> en=ImageEnhance.Brightness(wm)
>>> mask=en.enhance(0.5)
>>> im.paste(wm,(25,25),mask)
>>> im.show()
>>> 

Here, the alpha channel of 'mask' is used as the mask.

max




More information about the Python-list mailing list