How to add a watermark to an image using a python pillow
This tutorial is on How to add a watermark to an image using a python pillow. An image watermark is definitely one of the better ways to protect your images from misuse. it is recommended to add a watermark to your creative photos, before sharing them on social media. A watermark is generally some text or logo overlaid on the photo.
Python pillow package allows us to add watermarks to your images. We need Image, ImageDraw, and ImageFont modules from the pillow package. The ImageDraw module adds functionality to draw 2D graphics onto new or existing images.
Example
# How to add watermark to an image using python pillow # Import Image library from PIL import Image, ImageDraw, ImageFont im = Image.open('watermark.png').convert('RGBA') width, height = im.size draw = ImageDraw.Draw(im) wotermark_text = "watermark devnote" # times-new-roman.ttf font add font = ImageFont.truetype('times-new-roman.ttf', 60) textwidth, textheight = draw.textsize(wotermark_text, font) margin = 15 a = width - textwidth - margin b = height - textheight - margin # bottom right corner draw watermark draw.text((a, b), wotermark_text, font=font, fill=(255,255,255,255)) # Save watermarked im.save('devnote.png')