Skip to content

The parameter direction of ImageDraw.text can't use Chinese sequence #3125

@xyl576807077

Description

@xyl576807077

What did you do?

  1. I try to draw chinese character by following test code
from PIL import Image, ImageDraw, ImageFont
size = 32
font = ImageFont.truetype('./font/simsun.ttf', size)
img = Image.new('RGBA', (size, size), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
draw.text((0, 0), '我和你',  fill='black', direction='ttb')
  1. Futhermore, if I don't use chinese, just english:
from PIL import Image, ImageDraw, ImageFont, features
size = 32
img = Image.new('RGBA', (size, size), (255, 255, 255))
draw = ImageDraw.Draw(img)
draw.text((0, 0), 'abc', fill='black', direction='rtl')

What did you expect to happen?

  1. I want to get the image like that
我
和
你
  1. I want to get the image
    aa

What actually happened?

  1. The code can't run successfully. The log is
Traceback (most recent call last):
  File "draw_character.py", line 111, in <module>
    draw.text((0, 0), '我和你',  font=font, fill='black', direction='ttb')
  File "/home/xyl/anaconda3/lib/python3.6/site-packages/Pillow-5.0.0-py3.6-linux-x86_64.egg/PIL/ImageDraw.py", line 220, in text
  File "/home/xyl/anaconda3/lib/python3.6/site-packages/Pillow-5.0.0-py3.6-linux-x86_64.egg/PIL/ImageFont.py", line 166, in getmask2
RuntimeError: raqm_layout() failed.

The font file can be downloaded in here: https://github.com/micmro/Stylify-Me/blob/master/.fonts/SimSun.ttf
2. I get the image like this:
hehe

What versions of Pillow and Python are you using?

python: 3.6.3
pillow: 5.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.Font Rendering

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions