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
{{ message }}
Repository navigation
Is it possible to use colored Whatsapp/Facebook emoji? #3346
Noto Emoji gives black and white emojis, and Noto Color Emoji fails to load with OSError: invalid pixel size. I'm using Pillow 7.0.0 on Ubuntu.
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.
Additionally, freetype must be built with libpng to support this font (png bitmaps). However, due to #960, bitmap fonts will not work with Pillow at all. And even if they did, you would get a grayscale version of the emojis, because Pillow only returns one channel from the C layer font functions.
Note: I am working on improving some of this, I just need to write some tests to submit a PR.
it looks like FreeType 2.10.0 adds support for COLR/CPAL tables, which Noto Color Emoji uses for scalable color emoji glyphs. could this be taken advantage of to add support for this type of emoji font to Pillow?
@boringcactus I've got it partially implemented, but it is not PR ready. I'm not sure when I'll have time to work on it, but it will be either next week or a few weeks later.
@boringcactus I've got it partially implemented, but it is not PR ready. I'm not sure when I'll have time to work on it, but it will be either next week or a few weeks later.
I ended up working on #4724 first 😄 and postponed this until that gets merged to avoid merge conflicts. Thinking about it again, I don't think these two actually conflict too badly, so perhaps I can submit this soon as well. I'm hoping both of these can be included in version 8.0.0 planned for release in 6 weeks.
See my branch nulano/Pillow@06ba083...nulano:ft-color. IIRC it should work, but there are some extra unnecessary changes that should be removed, and parts of it can be simplified, before submitting it as a PR. Please treat it as a WIP, the API will likely change in the final version.
Hey, thank you so much, the new version installed correctly
However, it seems that fonts with color don't work, can you tell me what is wrong with this code?
For backwards compatibility you have enable color support using draw.text(..., embedded_color=True). This parameter might be renamed in the final version.
The best you can do for now is use unicodedata.category to break up text into "spans" each rendered separately with their own font. You can use font.getsize(...)[0] or draw.textsize(...)[0] as the horizontal offset between spans for now (#4724 proposes adding a faster and more precise font.getlength(...)). You will also have to handle linebreaks yourself, see draw.multiline_text for inspiration.
Pillow 8.0.0 has now been released, adding support for CBDT and COLR fonts. FreeType (and hence also Pillow ) does not yet support SBIX or SVG fonts.
To enable color support, use draw.text(..., embedded_color=True).
Edit: SBIX is supported in Pillow 8.0.0.
Edit2: FreeType 2.12 added support for SVG fonts via callbacks, see #6170 for implementing this in Pillow.
Reacted by Mikhail, Hugo van Kemenade, owocado, Goel Biju, Yamada Takahito, sergeybe2, Hunt Zhan, Robin Jacob Roy and Андрей
Reacted by Mehdi, Hugo van Kemenade, Mike Petrov and Андрей
Activity
guitar9 commentedon Sep 11, 2018
I think this is not implemented. But have somebody ideas to do a workaround? For example to tranform the emoji to a image and open the image and render it in text.
http://www.unicode.org/emoji/charts/full-emoji-list.html
https://github.com/carpedm20/emoji
hugovk commentedon Sep 11, 2018
A workaround is to call something like ImageMagick to create an image of the emoji, then open that.
For example, https://stackoverflow.com/a/52131155/724176
guitar9 commentedon Sep 11, 2018
this does not work under linux
hugovk commentedon Nov 20, 2019
Does this still happen?
How about when using a Noto font?
Exploder98 commentedon Apr 9, 2020
Noto Emoji gives black and white emojis, and Noto Color Emoji fails to load with
OSError: invalid pixel size. I'm using Pillow 7.0.0 on Ubuntu.nulano commentedon Apr 10, 2020
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.
Additionally, freetype must be built with libpng to support this font (png bitmaps). However, due to #960, bitmap fonts will not work with Pillow at all. And even if they did, you would get a grayscale version of the emojis, because Pillow only returns one channel from the C layer font functions.
Note: I am working on improving some of this, I just need to write some tests to submit a PR.
boringcactus commentedon Jun 19, 2020
it looks like FreeType 2.10.0 adds support for COLR/CPAL tables, which Noto Color Emoji uses for scalable color emoji glyphs. could this be taken advantage of to add support for this type of emoji font to Pillow?
nulano commentedon Jun 19, 2020
@boringcactus I've got it partially implemented, but it is not PR ready. I'm not sure when I'll have time to work on it, but it will be either next week or a few weeks later.
GanerCodes commentedon Aug 30, 2020
cough
nulano commentedon Aug 30, 2020
I ended up working on #4724 first 😄 and postponed this until that gets merged to avoid merge conflicts. Thinking about it again, I don't think these two actually conflict too badly, so perhaps I can submit this soon as well. I'm hoping both of these can be included in version 8.0.0 planned for release in 6 weeks.
GanerCodes commentedon Aug 31, 2020
Ah thanks, if you have the patch could you send it to me? I can implement it locally
nulano commentedon Aug 31, 2020
See my branch nulano/Pillow@06ba083...nulano:ft-color. IIRC it should work, but there are some extra unnecessary changes that should be removed, and parts of it can be simplified, before submitting it as a PR. Please treat it as a WIP, the API will likely change in the final version.
GanerCodes commentedon Aug 31, 2020
Hey, can you send me a compiled version for windows?
1 remaining item
GanerCodes commentedon Aug 31, 2020
I'm dumb, how do I install it with that?
hugovk commentedon Aug 31, 2020
Not dumb, it's not so obvious! :)
If you click dist"-ft-color" under Artifacts it'll download a zip file.
Extract that, and then
pip install filename.whl, wherefilename.whlis the one that closest matches your system (e.g.cp38for Python 3.8).GanerCodes commentedon Aug 31, 2020
Hey, thank you so much, the new version installed correctly
However, it seems that fonts with color don't work, can you tell me what is wrong with this code?
nulano commentedon Aug 31, 2020
For backwards compatibility you have enable color support using
draw.text(..., embedded_color=True). This parameter might be renamed in the final version.GanerCodes commentedon Aug 31, 2020
POG IT WORKS thank you so much man
GanerCodes commentedon Aug 31, 2020
Also, is there a way to have a secondary font for mission glyphs? like many fonts don't have emoji and ideally I want to support them still
nulano commentedon Aug 31, 2020
See #4808. Edit: fix link typo.
The best you can do for now is use
unicodedata.categoryto break up text into "spans" each rendered separately with their own font. You can usefont.getsize(...)[0]ordraw.textsize(...)[0]as the horizontal offset between spans for now (#4724 proposes adding a faster and more precisefont.getlength(...)). You will also have to handle linebreaks yourself, seedraw.multiline_textfor inspiration.nulano commentedon Oct 14, 2020
Pillow 8.0.0 has now been released, adding support for CBDT and COLR fonts.
FreeType (and hence alsoPillow)does not yet supportSBIX orSVG fonts.To enable color support, use
draw.text(..., embedded_color=True).Edit: SBIX is supported in Pillow 8.0.0.
Edit2: FreeType 2.12 added support for SVG fonts via callbacks, see #6170 for implementing this in Pillow.
jdhao commentedon Mar 31, 2022
@nulano I tried Pillow 9.0 and it seems that I still can not use noto color emoji font. The same error persists:
radarhere commentedon Mar 31, 2022
@jdhao would you be able to create a new issue with a self-contained example, and information about your environment?
jdhao commentedon Mar 31, 2022
Okay, will do it: #6166.
shula commentedon Feb 26, 2025
@nulano How to obtain the size of a font?
How do you know that NotoColorEmoji will render in 109 pixels?
radarhere commentedon Feb 28, 2025
I'm not sure what kind of answer you're interested in.
If you're asking how you can determine that using Pillow,
will try all font sizes between 1 and 500 and then only print