Watermark Photos with Python

GeoSense ✅
2 min readNov 25, 2022

A watermark is usually some text or a logo overlaid on the photo that identifies who took the photo or who owns the rights to the photo.

To watermark photos using Python, you can use the Python Imaging Library (PIL) or OpenCV library. Both libraries provide tools for image processing and can be used to add a watermark to an image.

The first thing you need to do is install Pillow if you haven’t already:

pip install pillow
Source: Author photo MG_5329.JPG

Adding a Text Watermark

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont


def watermark_text(input_image_path,
output_image_path,
text, pos):
photo = Image.open(input_image_path)

# make the image editable
drawing = ImageDraw.Draw(photo)

black = (3, 8, 12)
# font = ImageFont.truetype("Pillow/Tests/fonts/FreeMono.ttf", 40)
font = ImageFont.truetype("arial.ttf", 40)
# font = ImageFont.load_default()
drawing.text(pos, text, fill=black, font=font)
photo.show()
photo.save(output_image_path)


if __name__ == '__main__':
img = 'IMG_5329.JPG'
watermark_text(img, 'MG_5329.JPG_text.jpg',
text='TNMTHAI.com',
pos=(0, 0))

Here’s the result:

--

--

GeoSense ✅
GeoSense ✅

Written by GeoSense ✅

🌏 Remote sensing | 🛰️ Geographic Information Systems (GIS) | ℹ️ https://www.tnmthai.com/medium

Responses (3)