[Python] Quick Watermark Example with PIL

I created captcha sample long time ago but this time, it’s much simple example. If you would like to generate images with your logo, it’s only few lines of code in PIL.


import Image
baseim = Image.open(“original.png”)
logoim = Image.open(“logo.png”) #transparent image
baseim.paste(logoim,(baseim.size[0]-logoim.size[0],baseim.size[1]-logoim.size[1]),logoim)
baseim.save(‘new.png’,‘PNG’)

Important thing is the 3rd argument of the paste function. You can specify your PNG as alpha also so that you avoid black background.

here is the original image

and this is the logo

then this is the image after watermarking

python, image

By: kiichi on: