Python Thumbnails

What is this?

This is a script for me to generate video thumbnails for none video publications. I am way to lazy to create thumbnails so this just does it automaticly.

# Python image processing imports. Handling text and other things.
from PIL import Image, ImageDraw, ImageFont
# This if for text wrapping. Using \n isn't supported in PIL text
# stuff.
import textwrap

Open the image

In a directory I store background.png here I just open it so I can manipulate it.

# Image open and draw
image = Image.open("background.png")
draw = ImageDraw.Draw(image)

Add the text

Ask for input, run it through text wrap, specify a font I have in the directory and finally put it on the image.

# Text
text = input('Text: ')
textwrapped = textwrap.wrap(text, width=30)
dubai = ImageFont.truetype("ReemKufi-Regular.ttf", 100)
draw.text((400,400), '\n'.join(textwrapped), font=dubai, fill="#EE7A2F")

Saving it

I do some manipulation on the text variable so I get a nicer file name.

filename = text.replace(' ', '-')+".png"
image.save(filename, "PNG")
image.show()

Codeberg link

https://codeberg.org/zortazert/Python-Projects/src/branch/main/thumbnail