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

Unable to use NotoColorEmoji: invalid pixel size #6166

Closed
jdhao opened this issue Mar 31, 2022 · 5 comments
Closed

Unable to use NotoColorEmoji: invalid pixel size #6166

jdhao opened this issue Mar 31, 2022 · 5 comments
Labels

Comments

@jdhao
Copy link

jdhao commented Mar 31, 2022

What did you do?

I am trying to use NotoColorEmoji font from here.
Here is my code:

from PIL import ImageFont

FONT_PATH = './NotoColorEmoji.ttf'
font_size = 20
font = ImageFont.truetype(FONT_PATH, size=font_size)

What did you expect to happen?

I can open the font without error.

What actually happened?

I am seeing the following error:

     font = ImageFont.truetype(FONT_PATH, size=font_size)
   File "/home/jdhao/tools/miniconda/lib/python3.7/site-packages/PIL/ImageFont.py", line 844, in truetype
     return freetype(font)
   File "/home/jdhao/tools/miniconda/lib/python3.7/site-packages/PIL/ImageFont.py", line 841, in freetype
     return FreeTypeFont(font, size, index, encoding, layout_engine)
   File "/home/jdhao/tools/miniconda/lib/python3.7/site-packages/PIL/ImageFont.py", line 194, in __init__
     font, size, index, encoding, layout_engine=layout_engine
 OSError: invalid pixel size

What are your OS, Python and Pillow versions?

  • OS: CentOS 7.4
  • Python: 3.7.6
  • Pillow: 9.0.0
@nulano
Copy link
Contributor

nulano commented Mar 31, 2022

#3346 (comment)

This error is due to a freetype limitation. Bitmap fonts don't support scaling with freetype, so you must specify a valid size, which is 109 for Noto Color Emoji.

@nulano
Copy link
Contributor

nulano commented Mar 31, 2022

Google has proposed a new scalable format for colored fonts, COLR v1.

An experimental version of Noto Color Emoji should be available here: https://github.com/googlefonts/color-fonts
However, I don't think FreeType has full support for COLR v1 yet.

Edit: I think there is also an SVG version somewhere, FreeType has just added support for SVG fonts, but the required callbacks aren't added to Pillow yet: #6170

@radarhere
Copy link
Member

However, I don't think FreeType has full support for COLR v1 yet.

No, from what I can see, "an experimental interface" was added in 2.11.0.

@jdhao you liked the previous comment. Has this answered your question?

@jdhao
Copy link
Author

jdhao commented Apr 1, 2022

@radarhere The ultimate goal is to use the color emoji font as expected. Judging from the comment, this is not possible for now? My upvote is just for the clarification 😂

@jdhao
Copy link
Author

jdhao commented Apr 1, 2022

Okay, based on code this pr, I figured out. We need to change font size to exactly 109, then it should be fine.

from PIL import ImageFont

FONT_PATH = './NotoColorEmoji.ttf'
font_size = 109
font = ImageFont.truetype(FONT_PATH, size=font_size)

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

No branches or pull requests

3 participants