Create watermarks

We can use the ImageDraw module to create watermarks on our images. Here is how I would create a watermark text that says geek-university.com in the bottom left corner of the image.

First, I need to specify the text:

text = 'geek-university.com'

Next, I will specify the font family and size:

font = ImageFont.truetype(“OpenSans-ExtraBold.ttf”, size=50)

On Windows, Pillow will search the Windows fonts folder for the specified font. If you get an error, make sure to specify the full path to the font (e.g. r”C:\Windows\Fonts\Arial.ttf”). On Linux, make sure that the font you specify exist in the /usr/share/fonts directory.

Finally, I will use the text method to create a watermark:

idraw.text((10, 1500), text, font=font)

The first parameter is the tuple of the upper left corner of the text. The second is the text that will be displayed, and the last one is the font definition. The full code looks like this:

from PIL import Image, ImageDraw, ImageFont

img = Image.open('handsome.jpg')

idraw = ImageDraw.Draw(img)

text = 'geek-university.com'
font = ImageFont.truetype("OpenSans-ExtraBold.ttf", size=50)
idraw.text((10, 1500), text, font=font)

img.show()

The result:

Geek University 2022