Drawing text on an image

We can add text to an image using the text() function from the PIL.ImageDraw module, as shown in the next Python code snippet:

draw = ImageDraw.Draw(im)font = ImageFont.truetype("arial.ttf", 23) # use a truetype fontdraw.text((10, 5), "Welcome to image processing with python", font=font)del drawim.show()

The following figure shows the output image generated by running the previous code:

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.