Skip to content

ImageFont module: getsize is slow? #4651

@cristianocca

Description

@cristianocca

What did you do?

See code sample.

What did you expect to happen?

getsize should be fast. I'm trying to use this to implement a text-wrap mechanism (for SVGs), but the moment I add a single call to this in a for loop, timers go up 10 to 20 times slower.

Calling getsize on small text multiple times adds a significant overhead. I wonder if it can be improved somehow, or it is really as good as it can get. For example, 50 calls takes about 50ms (with short text), and increases significantly the bigger the text.

What actually happened?

getsize is slow.

What are your OS, Python and Pillow versions?

  • OS: Windows
  • Python: 3.7
  • Pillow: 7.1.2
font = ImageFont.truetype(font_file, font_size)

# Run the following in a loop
font.getsize(text)

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