镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Font rendering issue with ttc font #7871

Closed

Description

@camprevail

What did you do?

It seems that font rendering changed for the worse between 7.2.0 and 8.x, not sure which version exactly. (edit, it changed between 7.2 and 8.0). I had this issue a few years ago when I tried to upgrade to 8.x so I had to revert, but now I really have a need to upgrade.
Below is a comparison image, with the caption text rendered with draw.text() in Pillow 7.2.0 on the left and 10.2 on the right. On the right, you can see that the text appears to have lost it's softer anti-aliased look and kerning in some spots - some letters are touching each other.
I searched up and down and couldn't find any other reports of anything like this, I did try a few suggestions like setting draw.textmode = 'L' and enabling the kern feature, but nothing worked.

All I'm looking for is a solution or suggestions to get the old look back. The font used is msgothic.ttc, index 1.

diffs

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.10.11
  • Pillow: 10.2
base = Image.open('assets/misc/bg_new.png').convert('RGB')
draw = ImageDraw.Draw(base)
draw.fontmode = 'L'
caption_font = ImageFont.truetype("assets/font/msgothic.ttc", size=12, index=1)
text = "Warrior with a fan. She fights with the force of\nthe wind. She has a very strong personality,..."
draw.text((171, 780), text, (164, 144, 64), font=caption_font)
base.show()

Activity

  1. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Small update, tried changing the layout engine for this font object to layout_engine=ImageFont.Layout.BASIC. That seems to kind of fixed the kerning issue, but the antialias setting with draw.fontmode = 'L' still does nothing, no difference from setting it to '1'.
    I don't think antialias will fix the overall look of it being completely different... it almost doesn't look like the same font?
    test2

  2. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Tried switching to arial and it looks much better. Perhaps this is a problem with the msgothic TTC, or TTC font rendering specifically?
    test3

  3. changed the title [-]Font rendering changed after 7.2.0, looks worse now. [/-] [+]Font rendering changed after 7.2.0, not rendering TTC font correctly.[/+] on Mar 12, 2024
  4. changed the title [-]Font rendering changed after 7.2.0, not rendering TTC font correctly.[/-] [+]Font rendering changed after 7.2.0, not rendering TTC font correctly[/+] on Mar 12, 2024
  5. radarhere commented on Mar 12, 2024

    @radarhere
    Member

    It seems like you're uploading screenshots of the images, rather than the images themselves. Moving forward, I think it would be more helpful to have the images themselves.

    I'm guessing that you're installing Pillow from the wheels, using something like python3 -m pip install Pillow?

    font rendering changed for the worse between 7.2.0 and 8.x, not sure which version exactly.

    If you could figure out exactly which version, that would be interesting.

  6. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    I uploaded screenshots because the rest of the image is much larger and irrelevant, I really only needed to show the affected area, but if I do more tests I guess I'll just try to make a smaller canvas with text only that can be uploaded here.

    And yeah I installed via pip.

  7. radarhere commented on Mar 12, 2024

    @radarhere
    Member

    I really only needed to show the affected area

    You could also just crop the original image? I think the screenshots are introducing an element of blurriness.

  8. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    I'm pretty confident they aren't, do you not see the difference between the two images? It looks pretty clear to me, even on my phone

  9. radarhere commented on Mar 12, 2024

    @radarhere
    Member

    I do see a difference. I was just trying to improve the quality of what we were looking at here - I don't think it's worth discussing further.

  10. changed the title [-]Font rendering changed after 7.2.0, not rendering TTC font correctly[/-] [+]Font rendering issue with ttc font in 10.1.0 onwards[/+] on Mar 12, 2024
  11. changed the title [-]Font rendering issue with ttc font in 10.1.0 onwards[/-] [+]Font rendering issue with ttc font[/+] on Mar 12, 2024
  12. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Sorry, forgot to add the font arg to draw.text. Looks like it changed between 7.2 and 8.0. Here's the comparison images
    pillowtest-7 2 0
    pillowtest-8 0
    My code is:

    from PIL import Image, ImageDraw, ImageFont
    
    font = ImageFont.truetype('msgothic.ttc', size=12, index=1)
    base = Image.new('RGB', (250, 50), color=(255, 255, 255))
    draw = ImageDraw.Draw(base)
    mytext = 'The quick brown fox jumps over...'
    
    draw.text((5, 10), mytext, (0,0,0), font=font)
    base.show()
  13. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Here's a much better test revealing that something is happening between 22 and 23pt sizes.
    pillowtest-7 2 0
    pillowtest-8 0 0

  14. nulano commented on Mar 12, 2024

    @nulano
    Contributor

    Based on the images, this is almost certainly caused by #4955 fixing #891. The previous behaviour was caused by a bug where Pillow was ignoring embedded bitmaps in a font.

    OpenType fonts can contain embedded bitmaps in the EBDT table. This is supposed to provide better quality when rendering at small font sizes. Unfortunately, it seems that the font you are using did not implement this very well. You may be able to remove the embedded bitmap table with a tool such as FontForge.

  15. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Alright thanks for the suggestion, that worked and was very easy.
    pillowtest-10 2 0

  16. radarhere commented on Mar 12, 2024

    @radarhere
    Member

    Thanks very much nulano.

    Is this resolved then?

  17. camprevail commented on Mar 12, 2024

    @camprevail
    Author

    Yeah I suppose so. I'll close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions