Skip to content

text_width property of FontMetric doesn't seem accurate #618

Answered by emcconville
ProfessorSalty asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a better way to do this?

Have you tried just generating the text as a new image, and composing over the source image?

from wand.image import Image

kFontPath = '/usr/share/fonts/google-noto-vf/NotoSans-VF.ttf'


def faster_generate_message(msg):
    with Image(filename='wizard:') as img:
        dim = img.size
        with Image() as txt:
            # Set typeface properties before reading label:
            txt.background_color = 'transparent'
            txt.font_color = 'magenta'
            txt.font_path = kFontPath
            # Picking either the min / max will generate a real large image.
            txt.font_size = min(*dim)
            txt.read(filename='label:' + msg)…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ProfessorSalty
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants