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

Thai font not supported anymore #7747

Closed
Louis-de-Bontin opened this issue Jan 23, 2024 · 8 comments
Closed

Thai font not supported anymore #7747

Louis-de-Bontin opened this issue Jan 23, 2024 · 8 comments

Comments

@Louis-de-Bontin
Copy link

Louis-de-Bontin commented Jan 23, 2024

What did you do?

I am trying to write Thai text on an image.

What did you expect to happen?

Using the following code works perfectly fine in v8.1.2 (see image):
image

What actually happened?

But in v9.0.1, 9.1.1 and 10.2.0, some characters are overlapping (see image):
image

ImageDraw.Draw(image).text(
    (x, y),
    "หนึ่งร้อยสี่สิบบาทถ้วน",
    font="DroidSansThai.ttf",
    fill=color,
    allign="right",
    anchor="rs",
)

What are your OS, Python and Pillow versions?

  • OS: debian:bullseye-slim
  • Python: 3.9.2 and 3.10.12
  • Pillow: 8.1.2 works fine but 9.0.1, 9.1.1 and 10.2.0 are impacted

Note

I tried many fonts, the problem remains whatever the font. For the record, here are the ones I tested:

  • K2D-Regular.ttf
  • NotoSerifThai-VariableFont_wdth,wght.ttf
  • DroidSansThai.ttf
  • LomaThin.ttf
@radarhere
Copy link
Member

Looking at the images that you've attached, I think you prefer BASIC layout rather than RAQM, and I expect that the change occurred in 8.2.0.

When you are opening your font, if you attach layout_engine=ImageFont.Layout.BASIC like so,

font = ImageFont.truetype("./DroidSansThai-Regular.ttf", 124, layout_engine=ImageFont.Layout.BASIC)

you should get the result you prefer.

@nulano
Copy link
Contributor

nulano commented Jan 23, 2024

I agree with @radarhere about which change caused this. but I think you might have the opposite problem, i.e. that you were using RAQM layout before and use BASIC layout now.

If @radarhere's suggestion does not fix your issue, please answer the following:

How did you install Pillow?
What output do you get for python -m PIL with each version (please paste the beginning of the output up to the line starting with XCB support, once for Pillow 8.1.2 and once for a recent version to compare)?

@Louis-de-Bontin
Copy link
Author

Louis-de-Bontin commented Jan 24, 2024

To answer @radarhere , when adding layout_engine=ImageFont.Layout.BASIC, the output is the following (v9.0.1):

Traceback (most recent call last):
  File "/home/clovis1er/Documents/code/newlogic/png_test/test.py", line 47, in <module>
    font = ImageFont.truetype("DroidSansThai.ttf", 60, layout_engine=ImageFont.Layout.BASIC)
AttributeError: module 'PIL.ImageFont' has no attribute 'Layout'

To answer @nulano ,
This issue has been noticed by myself and my coworker, on both our local machines, as well as on odoo.sh. I can't say how Pillow has been installed for my coworker, or on odoo.sh, but for myself, I simply ran pip3 install Pillow==<version> in a venv virtual environment.

Here is the output of python -m PIL:
--- XCB (X protocol) support ok

@radarhere
Copy link
Member

radarhere commented Jan 24, 2024

To answer @radarhere , when adding layout_engine=ImageFont.Layout.BASIC, the output is the following (v9.0.1):

ImageFont.Layout.BASIC was only added in 10.0.0. To be less version specific, could you try layout_engine=0 instead?

@nulano
Copy link
Contributor

nulano commented Jan 24, 2024

Here is the output of python -m PIL:
--- XCB (X protocol) support ok

I mean the first ~22 lines (i.e. from the first output line to the XCB line). In particular, the FREETYPE2 and RAQM lines are relevant here, but there could be something else helpful in there as well.

@Louis-de-Bontin
Copy link
Author

@radarhere layout_engine=0 seems to be working, here is my output with v9.0.1:
image

@nulano Even though the problem is solved now, here is the output of python -m PIL, for the record:

--------------------------------------------------------------------
Pillow 9.0.1
Python 3.10.11 (main, Apr  5 2023, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]
--------------------------------------------------------------------
Python modules loaded from /home/clovis1er/Documents/code/newlogic/png_test/env/lib64/python3.10/site-packages/PIL
Binary modules loaded from /home/clovis1er/Documents/code/newlogic/png_test/env/lib64/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 9.0.1
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.11.1
--- LITTLECMS2 support ok, loaded 2.13
--- WEBP support ok, loaded 1.2.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 2.1.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.4.0
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.11
--- LIBTIFF support ok, loaded 4.3.0
--- RAQM (Bidirectional Text) support ok, loaded 0.7.2, fribidi 1.0.11, harfbuzz 3.2.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------

@radarhere
Copy link
Member

the problem is solved now

Is there anything more we can do for you?

@Louis-de-Bontin
Copy link
Author

No, thank you very much for your support @radarhere !
You can mark this issue as solved.

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

No branches or pull requests

4 participants