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

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

Closed

Description

@nissansz

image

Activity

  1. nissansz commented on Aug 2, 2023

    @nissansz
    Author

    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

  2. radarhere commented on Aug 2, 2023

    @radarhere
    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

  3. nissansz commented on Aug 2, 2023

    @nissansz
    Author

    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).

  4. radarhere commented on Aug 2, 2023

    @radarhere
    Member

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

  5. nissansz commented on Aug 2, 2023

    @nissansz
    Author

    Thank you.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions