I made a very simple pillow code that just shows text into a specific dialogue image i have. For now it's just a png file, but i'd like it so instead of just a png file, it gradually shows up the text in a GIF file, just like a dialogue system from undertale or whatever. The code follows:
from PIL import Image, ImageFont, ImageDraw
import textwrap
msg = "This is a test message."
font = ImageFont.truetype("dialouge_font.ttf", 28)
img = Image.open("catto.png")
cx, cy = (336, 97)
lines = textwrap.wrap(msg, width=45)
print(lines)
bbox = font.getbbox(msg)
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
y_text = cy - (h / 2) + 30
for line in lines:
draw = ImageDraw.Draw(img)
bbox2 = font.getbbox(line)
w, h = bbox2[2] - bbox2[0], bbox2[3] - bbox2[1]
draw.text((cx, y_text), line, (255, 255, 255), font=font)
img.save("catto_say.png")
y_text += h + 5
The output image is attached to the post.