You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ImageDraw.Draw.textsize fails with Indic fonts #2620
import os
from PIL import Image, ImageFont, ImageDraw
mode = 'RGB'
size = (100, 64)
im = Image.new(mode, size)
draw = ImageDraw.Draw(im)
fonts_dir = os.path.expanduser('~/.fonts/')
font_telugu = ImageFont.truetype(os.path.join(fonts_dir, "Vani.ttf"), 28)
text = "నిత్య"
w, h = draw.textsize(text)
What did you expect to happen?
Get width/height
What actually happened?
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/chillaranand/projects/likitham/create_likitham_dataset.py", line 16, in <module>
w, h = draw.textsize(text)
File "/home/chillaranand/.virtualenvs/py35/lib/python3.5/site-packages/Pillow-4.2.0-py3.5-linux-x86_64.egg/PIL/ImageDraw.py", line 260, in textsize
File "/home/chillaranand/.virtualenvs/py35/lib/python3.5/site-packages/Pillow-4.2.0-py3.5-linux-x86_64.egg/PIL/ImageFont.py", line 110, in getsize
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-4: ordinal not in range(256)
>>>
What versions of Pillow and Python are you using?
pip show pillow
Name: Pillow
Version: 4.2.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (Fork Author)
Author-email: [email protected]
License: Standard PIL License
Location: /home/chillaranand/.virtualenvs/py35/lib/python3.5/site-packages/Pillow-4.2.0-py3.5-linux-x86_64.egg
Requires: olefile
Activity
wiredfool commentedon Jul 14, 2017
I've replicated this on 3.5, but not 2.7.
wiredfool commentedon Jul 18, 2017
Your bug is here:
You need to pass in the font, or it draws with the default bitmapped font that's 8 bit only.
e.g.:
ChillarAnand commentedon Jul 18, 2017
Thanks @wiredfool