9951 explained code solutions for 126 technologies

python-pillowHow to add watermark to image

To add watermark, we first make it transparent with putalpha() and then merge our initial image with it:

from PIL import Image

im = Image.open('/var/www/examples/heroine.png')
im_merge = Image.open('/var/www/examples/watermark.png')

im.paste(im_merge, (0, 0), im_merge)

im.show()ctrl + c

import Pillow package modules


open given image with Pillow


change transparency of an image


paste given image to the current image

(0, 0)

coordinates to place watermark at


displays resulting image