Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating TrueType fonts with size=0 fails with Pillow 10+ differently than with Pillow 9 #7583

Closed
akx opened this issue Nov 28, 2023 · 0 comments · Fixed by #7584
Closed
Labels

Comments

@akx
Copy link
Contributor

akx commented Nov 28, 2023

What did you do?

(Pillow) ~/b/Pillow (main) $ docker run -it -v "./Arial Bold.ttf:/a.ttf:ro" python:3.11 bash
root@e1ff41aff78e:/# pip install 'pillow<10'
Successfully installed pillow-9.5.0
root@e1ff41aff78e:/# python
Python 3.11.6 (main, Nov  1 2023, 10:08:51) [GCC 12.2.0] on linux
>>> from PIL import ImageFont
>>> ImageFont.truetype("/a.ttf", size=0)
<PIL.ImageFont.FreeTypeFont object at 0xffff9ef7d990>
root@e1ff41aff78e:/# pip install 'pillow>=10'
Successfully installed pillow-10.1.0
root@e1ff41aff78e:/# python
Python 3.11.6 (main, Nov  1 2023, 10:08:51) [GCC 12.2.0] on linux
>>> from PIL import ImageFont
>>> ImageFont.truetype("/a.ttf", size=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 797, in truetype
    return freetype(font)
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 794, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/PIL/ImageFont.py", line 226, in __init__
    self.font = core.getfont(
                ^^^^^^^^^^^^^
OSError: invalid ppem value
>>>

What did you expect to happen? / What actually happened?

Font creation for a zero or negative size should fail alright, but maybe with a less cryptic error. (size=-1 yields invalid argument.)

With Pillow 9.x, font construction succeeds, but e.g. getbbox() or attempting to draw raises invalid argument.

What are your OS, Python and Pillow versions?

  • OS: Linux, various
  • Python: various
  • Pillow: see above for variants

See also

Downstream bug: WhyNotHugo/python-barcode#217

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants