Der Versuch, Python Pil imagedraw.textbbox wegen der Abschaltung von Texten zu verwenden, aber ich bekomme FehlerPython

Python-Programme
Anonymous
 Der Versuch, Python Pil imagedraw.textbbox wegen der Abschaltung von Texten zu verwenden, aber ich bekomme Fehler

Post by Anonymous »

Ich habe keine Probleme beim Schreiben von Text mit Texte, aber ich verstehe nicht, was ich mit TextBox falsch mache. Ich erhalte Fehler: < /p>

Datei
"c:\users\email\onedrive\Personal\Documents\Code\Python\TestPatternReTeNection /> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Code: Select all

from PIL import Image, ImageDraw, ImageFont

# Create an image object
img = Image.new("RGB", (400, 400), (255, 255, 255))

# Create a draw object
draw = ImageDraw.Draw(img)

# Define the font to be used for the text
font = ImageFont.truetype("arial.ttf", 36)

# Get the text bounding box
text = "Hello World!"
textwidth, textheight = draw.textbbox(text, font=font)

# Calculate the position for the text
x = (img.width - textwidth) / 2
y = (img.height - textheight) / 2

# Draw the text on the image
draw.text((x, y), text, (0, 0, 0), font=font)

# Save the image
img.save("hello_world.png")

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post