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

How to draw vertical text lines with font family? #7313

Closed
nissansz opened this issue Aug 2, 2023 · 5 comments
Closed

How to draw vertical text lines with font family? #7313

nissansz opened this issue Aug 2, 2023 · 5 comments
Labels

Comments

@nissansz
Copy link

nissansz commented Aug 2, 2023

image

@nissansz
Copy link
Author

nissansz commented Aug 2, 2023

I tried to write each char, effect is as follows, and it seems not as good as horizontal text draw, any direct vertical line draw method?
Some chars are not aligned in the middle.

for i, char in enumerate(text):
    draw.text((0, font_size * i), char, font=font_family , fill=(0, 0, 0)) 

image

@radarhere
Copy link
Member

There is the "direction" parameter of ImageDraw's text() method - https://pillow.readthedocs.io/en/stable/reference/ImageDraw.html#PIL.ImageDraw.ImageDraw.text

Direction of the text. It can be "rtl" (right to left), "ltr" (left to right) or "ttb" (top to bottom). Requires libraqm

from PIL import Image, ImageDraw, ImageFont

ttf = ImageFont.truetype("Tests/fonts/NotoSansJP-Regular.otf", 20)

im = Image.new(mode="RGB", size=(30, 220))
draw = ImageDraw.Draw(im)
draw.text((0, 0), "English あい", font=ttf, fill=500, direction="ttb")
im.save("out.png")

out

@nissansz
Copy link
Author

nissansz commented Aug 2, 2023

Thank you, what is effect of embedded color?

ImageDraw.text(xy, text, fill=None, font=None, anchor=None, spacing=4, align='left', direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False)[source]
Draws the string at the given position.

PARAMETERS:
xy – The anchor coordinates of the text.

text – String to be drawn. If it contains any newline characters, the text is passed on to multiline_text().

fill – Color to use for the text.

font – An ImageFont instance.

anchor –

The text anchor alignment. Determines the relative location of the anchor to the text. The default alignment is top left. See Text anchors for valid values. This parameter is ignored for non-TrueType fonts.

Note

This parameter was present in earlier versions of Pillow, but implemented only in version 8.0.0.

spacing – If the text is passed on to multiline_text(), the number of pixels between lines.

align – If the text is passed on to multiline_text(), "left", "center" or "right". Determines the relative alignment of lines. Use the anchor parameter to specify the alignment to xy.

direction –

Direction of the text. It can be "rtl" (right to left), "ltr" (left to right) or "ttb" (top to bottom). Requires libraqm.

New in version 4.2.0.

features –

A list of OpenType font features to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example "dlig" or "ss01", but can be also used to turn off default font features, for example "-liga" to disable ligatures or "-kern" to disable kerning. To get all supported features, see OpenType docs. Requires libraqm.

New in version 4.2.0.

language –

Language of the text. Different languages may use different glyph shapes or ligatures. This parameter tells the font which language the text is in, and to apply the correct substitutions as appropriate, if available. It should be a BCP 47 language code. Requires libraqm.

New in version 6.0.0.

stroke_width –

The width of the text stroke.

New in version 6.2.0.

stroke_fill –

Color to use for the text stroke. If not given, will default to the fill parameter.

New in version 6.2.0.

embedded_color –

Whether to use font embedded color glyphs (COLR, CBDT, SBIX).

New in version 8.0.0.

ImageDraw.multiline_text(xy, text, fill=None, font=None, anchor=None, spacing=4, align='left', direction=None, features=None, language=None, stroke_width=0, stroke_fill=None, embedded_color=False)[source]
Draws the string at the given position.

PARAMETERS:
xy – The anchor coordinates of the text.

text – String to be drawn.

fill – Color to use for the text.

font – An ImageFont instance.

anchor –

The text anchor alignment. Determines the relative location of the anchor to the text. The default alignment is top left. See Text anchors for valid values. This parameter is ignored for non-TrueType fonts.

Note

This parameter was present in earlier versions of Pillow, but implemented only in version 8.0.0.

spacing – The number of pixels between lines.

align – "left", "center" or "right". Determines the relative alignment of lines. Use the anchor parameter to specify the alignment to xy.

direction –

Direction of the text. It can be "rtl" (right to left), "ltr" (left to right) or "ttb" (top to bottom). Requires libraqm.

New in version 4.2.0.

features –

A list of OpenType font features to be used during text layout. This is usually used to turn on optional font features that are not enabled by default, for example "dlig" or "ss01", but can be also used to turn off default font features, for example "-liga" to disable ligatures or "-kern" to disable kerning. To get all supported features, see OpenType docs. Requires libraqm.

New in version 4.2.0.

language –

Language of the text. Different languages may use different glyph shapes or ligatures. This parameter tells the font which language the text is in, and to apply the correct substitutions as appropriate, if available. It should be a BCP 47 language code. Requires libraqm.

New in version 6.0.0.

stroke_width –

The width of the text stroke.

New in version 6.2.0.

stroke_fill –

Color to use for the text stroke. If not given, will default to
the fill parameter.

New in version 6.2.0.

embedded_color –

Whether to use font embedded color glyphs (COLR, CBDT, SBIX).

@radarhere
Copy link
Member

Embedded color is for fonts that have colors inside them. In #4955, an example of this is fonts that include emojis.
testemoji_cbdt

@nissansz
Copy link
Author

nissansz commented Aug 2, 2023

Thank you.

@nissansz nissansz closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants