How do I add a line of text to an image? Python

There is a picture, you need to add a line of text to it, which you can set. How do I do this with Python? You need to create a bot for the VC, for example, this bot. https://vk.com/memes_bot

Author: MaxU, 2018-07-17

1 answers

For example, use the PIL library.

The most simple example of drawing:

# pip install Pillow
from PIL import Image, ImageDraw, ImageFont

image = Image.open("images.jpg")

font = ImageFont.truetype("arial.ttf", 25)
drawer = ImageDraw.Draw(image)
drawer.text((50, 100), "Hello World!\nПривет мир!", font=font, fill='black')

image.save('new_img.jpg')
image.show()

Screenshot:

enter a description of the image here

 3
Author: gil9red, 2018-07-17 19:14:25