У меня нет проблем с написанием текста с текстом, но я не понимаю, что я делаю не так с TextBbox. Я получаю ошибку: < /p>
file
"c:lamesers\maildrive\personal\documents 8code\phothon\testpatternerator\test.py",
line 14, в
textwidth, textheight = dlaw.textbbox ("bront) /> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^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")
Подробнее здесь: https://stackoverflow.com/questions/753 ... cation-but
Попытка использовать Python pil imagedraw.textbbox из -за установления текстового определения, но я получаю ошибки ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Pillow ImageDraw.Draw.textsize выдает объект 'str', не имеющий атрибута 'getsize'
Anonymous » » в форуме Python - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-