#๐Ÿ”’ Add some sort of "dialogue effect" using pillow

11 messages ยท Page 1 of 1 (latest)

mellow marsh
#

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.

reef vigilBOT
#

@mellow marsh

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

pallid grail
mellow marsh
pallid grail
#

oh ok

delicate prawn
mellow marsh
# delicate prawn You could loop through the characters in the string to create your message one l...

tried adding it like this but didn't seem to work, just sends it as a gif

        frames = []
        
        cx, cy = (336, 95)
        
        msg = prompt
   
        font = ImageFont.truetype("dialouge_font.ttf", 30)
        text_length = len(msg)
        
        if character in ["big boi", "bigboi"]:
            img = Image.open("bigboi.png")
        elif character in ["catto boi", "catto", "cattoboi"]:
            img = Image.open("catto.png")
        else:
            await interaction.followup.send(f"Character '{character}' doesn't exist!", ephemeral=True)
            return
        

        for i in range(1, text_length + 1):
            current_text = msg[:i]
            lines = textwrap.wrap(current_text, width=40)
            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)
            y_text += h - 2
mellow marsh
#

nevermind, got it working

#

!close

reef vigilBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.