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
I get a type error saying that I cannot pass a Path object.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mauro/.pyenv/versions/test_env/lib/python3.10/site-packages/PIL/ImageFont.py", line 797, in truetype
return freetype(font)
File "/home/mauro/.pyenv/versions/test_env/lib/python3.10/site-packages/PIL/ImageFont.py", line 794, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/home/mauro/.pyenv/versions/test_env/lib/python3.10/site-packages/PIL/ImageFont.py", line 226, in __init__
self.font = core.getfont(
TypeError: argument 1 must be str, bytes or bytearray, not PosixPath
Funnily enough, the __init__ function of FreeTypeFont checks if the passed font argument is of type bytes, str or Path:
This makes me think, that the ImageFont.truetype() function should indeed accept Path objects and internally convert the argument into a string before fowarding it to core.getfont().
What are your OS, Python and Pillow versions?
OS: Ubuntu 22.04.3 LTS
Python: 3.10.7
Pillow: 10.1.0
The text was updated successfully, but these errors were encountered:
What did you do?
Pass
Path
object instead ofstr
toImageFont.truetype()
. IMO this should work if I understand the docs correctly.What did you expect to happen?
Get back a font object.
What actually happened?
I get a type error saying that I cannot pass a
Path
object.Funnily enough, the
__init__
function ofFreeTypeFont
checks if the passedfont
argument is of typebytes
,str
orPath
:Pillow/src/PIL/ImageFont.py
Line 215 in f9c7bd8
The problem occurs later when the
core
object should load the font which presumably only works iffont
is a string:Pillow/src/PIL/ImageFont.py
Lines 226 to 228 in f9c7bd8
This makes me think, that the
ImageFont.truetype()
function should indeed acceptPath
objects and internally convert the argument into a string before fowarding it tocore.getfont()
.What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: