Pillow: UnicodeEncodeError

Created on 18 Jul 2018  路  2Comments  路  Source: python-pillow/Pillow

Python 3.6.4, Pillow 5.2.0

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

font = ImageFont.truetype('10423.ttf', 70)
text = '18 懈褞谢褟'
img = Image.open('18144592.jpg')
draw = ImageDraw.Draw(img)
w1, h1 = draw.textsize(text)

An error occurred while executing the code:

dfcvbvcb

How can I fix it?

Font:
10423.zip

Question

Most helpful comment

You're using the default font, not 10423.ttf.

Change your last line to:

w1, h1 = draw.textsize(text, font)

Docs: https://pillow.readthedocs.io/en/latest/reference/ImageDraw.html#PIL.ImageDraw.PIL.ImageDraw.ImageDraw.textsize

All 2 comments

You're using the default font, not 10423.ttf.

Change your last line to:

w1, h1 = draw.textsize(text, font)

Docs: https://pillow.readthedocs.io/en/latest/reference/ImageDraw.html#PIL.ImageDraw.PIL.ImageDraw.ImageDraw.textsize

@hugovk
Thank you for your help. Everything is working!

Was this page helpful?
0 / 5 - 0 ratings