getsize() is throwing "{OSError}too many function definitions" for certain fonts
What did you do?
I tried to use a font called Singo and it works to read the font ImageFont.truetype(font="singo.ttf", size=14) but then I'm getting the error {OSError}too many function definitions when I try to get the text size. It is crashing in the function getsize() in the file ImageFont.py
I tried with two different font files, one of them works even though they look identical on my computer and I am able to install both on my computer. For reference, here are the two fonts; https://github.com/norahsakal/test-font-debugging
What did you expect to happen?
I expected to get the height and width from the font.
What actually happened?
The function getsize() in the file ImageFont.py is throwing the error {OSError}too many function definitions
What are your OS, Python and Pillow versions?
- OS: MacOS
- Python: 3.7
- Pillow: 8.2.0
Here is what I tried to do
from PIL import Image, ImageDraw
import PIL.ImageFont as ImageFont
draw = ImageDraw.Draw('image.pg')
font_text = ImageFont.truetype("singo.ttf", 13)
text = "Hello"
w, h = draw.textsize(text, font=font_text)
The error
File "/tmp/sls-py-req/PIL/ImageDraw.py", line 569, in textsize
return font.getsize(text, direction, features, language, stroke_width)
File "/tmp/sls-py-req/PIL/ImageFont.py", line 430, in getsize
size, offset = self.font.getsize(text, "L", direction, features, language)
OSError: too many function definitions
"too many function definitions" is actually a FreeType error - https://www.freetype.org/freetype2/docs/reference/ft2-error_code_values.html
I expect that the font is simply broken.
@norahsakal do you disagree?
Thank you so much for your prompt reply @radarhere, I truly appreciate it! Closing this 🙏
I had a similar issue and found that it was a broken font (ttf) file. I ended up finding an OTF version of the file and this helped.