-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Unimplemented feature when converting emojis to image #7854
Comments
This sounds like it might be a message from FreeType, the library used by Pillow to render text: Pillow/Tests/test_imagefont.py Lines 983 to 985 in 1b7bcfb
How did you install Pillow (on both systems)? What is the output of |
If it's helpful information, I'm on an M1 with macOS 14.3.1, and I don't see the error. Investigating, https://stackoverflow.com/questions/63742055/freetype-colour-rendering-ft-load-glyph-returns-unimplemented-feature suggests that FreeType being built without |
Hello, for my system (intel mac chip) I installed pillow using brew. > python3 -m PIL
--------------------------------------------------------------------
Pillow 10.2.0
Python 3.12.2 (main, Feb 6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
--------------------------------------------------------------------
Python modules loaded from /usr/local/lib/python3.12/site-packages/PIL
Binary modules loaded from /usr/local/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.2.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.1
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.0
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.12
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok
--------------------------------------------------------------------
BLP
Extensions: .blp
Features: open, save, encode
-------------------------------------------------------------------- @garymh could you share the results from your mac ? |
Sure:
This is with an Apple M1 Max |
So @garymh is the environment with the error? How did he install Pillow? |
@garymh I'm assuming you also installed Pillow using brew? Could you please provide the output of |
Sure, any relevant parts you're looking for though? I'm a dev so I have quite a few things installed 🙃 Here are python related things:
|
Everything related to the font stack. Unless I'm forgetting something, that should be freetype, harfbuzz, fribidi, libraqm, libpng. |
Got it!
|
Could you run the script without |
Nope :( I tried both:
and
Both gave me |
It may or may not be helpful, but could we get the full traceback, not just the error string? So the output of convert_emoji_to_png("🚶➡️") not just try:
convert_emoji_to_png("🚶➡️")
except Exception as e:
print(e) |
Sure: ❯ python3 emoji_test.py
Traceback (most recent call last):
File "/Users/gary/Desktop/emoji_test.py", line 14, in <module>
convert_emoji_to_png("🚶➡️")
File "/Users/gary/Desktop/emoji_test.py", line 11, in convert_emoji_to_png
draw.text(draw_position, emoji, font=font, embedded_color=False)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 568, in text
draw_text(ink)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 510, in draw_text
mask, offset = font.getmask2(
^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageFont.py", line 602, in getmask2
offset = self.font.render(
^^^^^^^^^^^^^^^^^
OSError: unimplemented feature |
I attempted to replicate in macOS 14 arm64 on GitHub Actions, with
but it passed. |
If you install Pillow from this PyPI wheel, does the problem still occur? I don't expect it to fix it, but if the error still occurs with this, that means I could potentially put together a wheel with better logging for you to run. If it doesn't, are you open to building Pillow from source? |
Closing this issue as no feedback has been received. |
The problem still persist on Pillow 10.3.0 @radarhere. --------------------------------------------------------------------
Pillow 10.3.0
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
--------------------------------------------------------------------
Python executable is /opt/homebrew/opt/[email protected]/bin/python3.12
System Python files loaded from /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12
--------------------------------------------------------------------
Python Pillow modules loaded from /opt/homebrew/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /opt/homebrew/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.12
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok using a from PIL import Image, ImageDraw, ImageFont
def convert_emoji_to_png(emoji, name):
image_size = (64, 64) # set image size
image = Image.new("RGBA", image_size, (0, 0, 0, 0)) # Set transparent background
font_size = 64 # Adjusted font size
font_path = "/System/Library/Fonts/Apple Color Emoji.ttc"
font = ImageFont.truetype(font_path, font_size, encoding='unic')
draw_position = (int((image_size[0] - font_size) / 2), int((image_size[1] - font_size) / 2))
draw = ImageDraw.Draw(image)
draw.text(draw_position, emoji, font=font, embedded_color=True)
image.save(f"{name.replace(':', '')}.png", "PNG")
convert_emoji_to_png("👩🦽➡️", 'test') outputs : python3 test.py
Traceback (most recent call last):
File "/Users/user/Documents/GitHub/alfred-emoji-wine/test.py", line 14, in <module>
convert_emoji_to_png("👩🦽➡️", 'test')
File "/Users/user/Documents/GitHub/alfred-emoji-wine/test.py", line 11, in convert_emoji_to_png
draw.text(draw_position, emoji, font=font, embedded_color=True)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 590, in text
draw_text(ink)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 529, in draw_text
mask, offset = font.getmask2(
^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageFont.py", line 592, in getmask2
return self.font.render(
^^^^^^^^^^^^^^^^^
OSError: unimplemented feature I tried the following without any positive result brew update
brew install [email protected] pillow freetype fribidi harfbuzz libpng libraqm |
Could you describe in words what you're expecting? The sequence of unicode characters being requested is - woman, zero width joiner, manual wheelchair, zero width joiner, black rightwards arrow, variation selector-16. If I trim the last two characters from the string, then it renders fine on my machine. |
I was trying to create an image from emoji using the native emoji font on macOS. What character did you trim exactly ? Is my emoji sequence not correct 🤨 ? FYI I am using this list as my emoji source |
It seems you are still using brew to install Pillow. If you are using a wheel from PyPI (e.g. the one linked by @radarhere above), you should see the following:
Could you please test with Pillow installed from PyPI? This one should work: https://files.pythonhosted.org/packages/5e/77/4cf407e7b033b4d8e5fcaac295b6e159cf1c70fa105d769f01ea2e1e5eca/pillow-10.3.0-cp312-cp312-macosx_11_0_arm64.whl This would at least let us know if the issue is specific to the brew build of Pillow (or other used libraries). |
@nulano now Pillow 10.3.0
Python 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]
--------------------------------------------------------------------
Python executable is /opt/homebrew/opt/[email protected]/bin/python3.12
System Python files loaded from /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.12
--------------------------------------------------------------------
Python Pillow modules loaded from /opt/homebrew/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /opt/homebrew/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.14, harfbuzz 8.4.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok python3 test.py
Traceback (most recent call last):
File "/Users/user/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.AE55F6CA-27EF-4215-979B-D0CE54F501D7/test.py", line 14, in <module>
convert_emoji_to_png("👩🦽➡️", 'test')
File "/Users/user/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.AE55F6CA-27EF-4215-979B-D0CE54F501D7/test.py", line 11, in convert_emoji_to_png
draw.text(draw_position, emoji, font=font, embedded_color=True)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 590, in text
draw_text(ink)
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageDraw.py", line 529, in draw_text
mask, offset = font.getmask2(
^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.12/site-packages/PIL/ImageFont.py", line 592, in getmask2
return self.font.render(
^^^^^^^^^^^^^^^^^
OSError: unimplemented feature |
I find that running convert_emoji_to_png("👩🦽➡️"[:-2], 'test') works. So from your emoji source, I find that 'woman in manual wheelchair', works, but 'woman in manual wheelchair facing right' doesn't. |
@radarhere I think the problem comes from the right arrow modifier then. All the following emojis have this modifier, here is an example here are the emojis causing problems :
|
I've sent an e-mail to FreeType asking them if they have any thoughts.
Hi,
Over at Python Pillow, a user has tried to render an emoji with macOS’ Apple Color Emoji.ttc - #7854 (comment). The emoji is the combination of ‘woman’ U+1F469, 'zero width joiner’ U+200D, 'manual wheelchair’ U+1F9BD, 'zero width joiner’ U+200D, 'black rightwards arrow’ U+27A1, 'variation selector-16’ U+FE0F, with the intention of being a woman in a manual wheelchair facing right. However, FreeType returns an Unimplemented_Feature error. Interesting, it only doesn’t do this for just a woman in a manual wheelchair. To demonstrate, the following code attempts to use woman in a manual wheelchair, and then woman in a manual wheelchair facing right. The error only occurs in the second instance. FT_Library library;
FT_Init_FreeType(&library);
FT_Face face = NULL;
FT_New_Face(library, "/System/Library/Fonts/Apple Color Emoji.ttc", 0, &face);
FT_Set_Pixel_Sizes(face, 0, 64);
int error = FT_Load_Glyph(face, 1507, FT_LOAD_DEFAULT);
if (error) {
printf("1507: error %d\n", error);
}
error = FT_Load_Glyph(face, 1508, FT_LOAD_DEFAULT);
if (error) {
printf("1508: error %d\n", error);
} I’ve attached images that, as far as I can see, show that both indexes are present in the font. Any thoughts as to why one should fail but not the other would be appreciated. Thanks. |
I still need to continue the conversation with FreeType, but here is part of the initial response.
|
@radarhere Thanks for the update ! I look forward to get a solution. Please, tell me if you need any other information / tests. |
Ok, after some further investigation, I found that the graphic type 'flip' is being used. This is a new feature from Apple (I can't even find documentation about it), and something that FreeType doesn't support yet. In my e-mails with FreeType, they have said that supporting this feature would be nice, and so I've created https://gitlab.freedesktop.org/freetype/freetype/-/issues/1282 |
The FreeType issue has now been resolved. The next step is to wait for a FreeType release. |
Many thanks for the update @radarhere 😊 |
What did you do?
Converting emoji text using
Apple Color Emoji.ttc
font to png file usingpillow
. The behavior is different between two macs. On one configuration (see below) the script is correctly generating images from all emoji and on the other hand, for another configuration, the script is returning an error for some emojis.What did you expect to happen?
What actually happened?
With the second cofiguration, the script returns
Note that it seems to be a problem only for emojis from 15.1 version, see this issue.
What are your OS, Python and Pillow versions?
Configuration where the script is working:
Configuration where the script returns an error:
The text was updated successfully, but these errors were encountered: