Skip to content

Support CJK in images.Text, add width and height as optional args #11364

Open
@naa0yama

Description

@naa0yama

When I started using Hugo, I was really drawn to the "images.Text" feature.
I'm trying to use this to generate images for the Open Graph Protocol.

Since it does not support CJK, it is in a state where it is not wrapped as shown below.

{{- $font := resources.Get "/fonts/NotoSansJP-Bold.ttf" -}}
{{- $img_base := resources.Get "/img/ogp.png" -}}
{{- $img_base = $img_base.Filter (images.Text "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみぬめもあいうえおかきくけこさしすせそたちつてとなにぬねの" (
        dict
            "color" "#ffffff"
            "size" 60
            "linespacing" 2
            "x" 130
            "y" 220
            "font" $font
        )
    )
-}}

ogp_hufdd91d49eff6d1dff05547c7d4a76f06_74228_59b8087107427e41d2c791161541b873

Workaround

As a workaround, it can be handled by separating with spaces at moderate intervals, but I thought it would be easier to use if you could define a text area like a CSS margin.
Could you consider adding it as a feature?

  • Avoidance example
{{- $img_base = $img_base.Filter (images.Text "あいうえおかきくけこさしすせそ たちつてとなにぬねのはひふへほ まみぬめもあいうえおかきくけ こさしすせそたちつてとなにぬねの" (
        dict
            "color" "#ffffff"
            "size" 60
            "linespacing" 2
            "x" 130
            "y" 220
            "font" $font
        )
    )
-}}

ogp_hufdd91d49eff6d1dff05547c7d4a76f06_74228_490208ae06a351d5c4cd8b1ac2e294fb

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions