Skip to content

Conversation

@radarhere
Copy link
Member

Currently, FreeTypeFont doesn't support bytes, while the less-used ImageFont does.

>>> from PIL import ImageFont >>> font = ImageFont.load_default() >>> font <PIL.ImageFont.FreeTypeFont object at 0x102bbac10> >>> font.getlength("test") 16.0 >>> font.getlength(b"test") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "PIL/ImageFont.py", line 353, in getlength return self.font.getlength(text, mode, direction, features, language) / 64 TypeError: expected string >>> from PIL import _util >>> ImageFont.core = _util.DeferredError(ImportError) >>> font = ImageFont.load_default() >>> font <PIL.ImageFont.ImageFont object at 0x102d23910> >>> font.getlength("test") 24 >>> font.getlength(b"test") 24

This adds byte support to FreeTypeFont.

@hugovk hugovk merged commit 563f45c into python-pillow:main Jun 25, 2024
@radarhere radarhere deleted the freetypefont_bytes branch June 25, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants