-
-
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
FreeType error when drawing text #7290
Comments
Hi. It looks like this is an error from FreeType, a dependency that Pillow uses to render text - https://freetype.org/freetype2/docs/reference/ft2-error_code_values.html You have said that the error is intermittent, which tends to be a hard type of problem to solve. To make life easier, a self-contained example could be helpful - code that we can run to trigger the problem, and all input files that the code uses. This would let us know what font you are using, and what text you are rendering. It would also help to know how often the error occurs, and if there is any kind of pattern to when it occurs. |
I collected many fonts, but forgot to print the error font name. |
方正悠黑系列_502L.zip from PIL import Image, ImageFont, ImageDraw
temp_canvas = Image.new("RGBA", (1200, 300), (255, 255, 255, 255))
draw_canvas = ImageDraw.Draw(temp_canvas, "RGBA")
path1 = r'F:\fonts\en\segoeui.ttf'
font = ImageFont.truetype(path1, size=50)
path2 = r'L:\paddle\字体制作\字体1000+款\01方正字体 (508款)\方正藏文新白体.TTF'
path2 = r'L:\paddle\字体制作\字体1000+款\01方正字体 (508款)\方正悠黑系列_512B.ttf'
path2 = r'L:\paddle\字体制作\字体1000+款\01方正字体 (508款)\方正悠黑系列_502L.ttf'
backup_font = ImageFont.truetype(path2, size=50)
path3 = r'F:\fonts\tianshiyanti2.0.ttf'
backup_font2 = ImageFont.truetype(path3, size=50)
font_family = ImageFont.FreeTypeFontFamily(backup_font, backup_font2)
text_string = "hello ಠಠ world"
text_string = "大家にほn中国制造12345잔치상 차렸어? 方正中倩简体.ttf"
draw_canvas.text((100, 100), text_string, fill="#000000", font=font_family)
temp_canvas.show() |
I need to use FreeTypeFontFamily. Other versions don't have this function, don't know whether there is such error. |
I've tested with normal Pillow, and I find that the error still occurs. from PIL import Image, ImageFont, ImageDraw
im = Image.new("RGB", (100, 100))
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('方正悠黑系列_502L.ttf')
draw.text((0, 0), "test", font=font) I can confirm that it is indeed coming from FreeType. I expect the font is broken. If you go to https://cloudconvert.com/ttf-converter and convert 方正悠黑系列_502L.ttf to an OTF font, and use that font instead, then it should work. I expect something in that conversion process has fixed the mistake in the font. |
thank you for the info. I will try to convert failed fonts. |
I can't say when/if #6926 will be included in Pillow. It is not actually complete yet - it is still marked as a draft. |
If we have given you all of that the help that you need, you can let us know by closing this issue. |
ok. Thank you. |
I got another error sometimes. string = "大家にほn中国制造12345잔치상 차렸어? 方正中倩简体.ttf" draw_canvas.text((x, y), text_string , fill="#000000", font=font_family, stroke_width=2, stroke_fill=(0, 0, 0))
File "D:\Python3.8.8\lib\site-packages\PIL\ImageDraw.py", line 514, in text
draw_text(stroke_ink, stroke_width)
File "D:\Python3.8.8\lib\site-packages\PIL\ImageDraw.py", line 463, in draw_text
mask, offset = font.getmask2(
File "D:\Python3.8.8\lib\site-packages\PIL\ImageFont.py", line
[Tetra decorative.zip](https://github.com/python-pillow/Pillow/files/12074355/Tetra.decorative.zip)
1155, in getmask2
self.font.render(
OSError: array allocation size too large |
That is also an error coming from FreeType. We recently had a report of this in #7287. I asked the FreeType support mailing list, and it turned out that the font was too complex. I would guess that the same thing is happening here. I suggest you first figure out which font is causing the problem. Try running your code with only one of the fonts at a time, and see when the error occurs. If you think that FreeType should work with this font as it currently exists, you can e-mail [email protected] (as per https://freetype.org/contact.html) to ask the FreeType community about it. If you would like help putting together that e-mail, please post the font files so that we can replicate the problem. There are many variations of the Noto font, so I don't know which one you're referring to specifically. However, as I said, the last time we contacted FreeType about a font with this error, they simply said it was there were too many points. Alternatively, you could contact whoever created the font, and see if they are aware of this problem and if they are willing to update their font to be simpler. |
Thank you. For some fonts, even after converted to otf, it does not work. And it seems some characters do not work, some may work. |
I'm unable to find NotoOldShapeNormal on Google. Are able to upload the font here? And Tetra decorative as well? |
Attached some fonts for you to try. You can use any other backup font you like, or don't use backup. |
From the fonts you've attached
The scope of this issue is increasing. It was originally about one font, now it is about at least five. It was originally about one error, now it is about at least two errors. What I'm trying to say is that we can't help you make every font work. Some fonts are broken. You are free to contact FreeType on your own about them if you think that FreeType should support them. Also, I don't think it's correct for us to try and solve your problems with #6926 here. That PR hasn't been merged yet. This means it is not ready, and you are using it at your own risk. If you think you have found a problem with that PR, that you think is not simply a broken font, you can comment there to offer helpful feedback as the PR progresses. But I don't think it is reasonable to expect it to always work, as it is not finished yet. |
Totally understand. |
win10, python 3.8, pillow 10, draw text sometimes has error as below. How to solve?
The text was updated successfully, but these errors were encountered: