python-pillow / python-pillow/Pillow

Automatic text wrapping/text box filling

Open
#6,201 27 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
13.8k
Forks
2.5k
Avg merge
2d 8h
Merged PRs (30d)
89

Description

many people have written scripts to do this and it's relatively easy with the library's getsize func but I feel like it really should be a built-in feature.

i think there should be a draw_text_box or similar function which has these properties on top of the existing draw_multiline_text:

  • you can specify a max width in pixels and Pillow will automatically insert line breaks to keep the text's width under the max width
    • I think there should be an option to only break at word boundaries unless the word exceeds the max width, like the CSS word-break property
  • you can specify a max height in pixels with one of two behaviors:
    • when reaching the max height, the text box is clipped and doesn't draw any more.
    • when reaching the max height, the font size is gradually reduced until the text fits inside
      • I think a min font size property would be useful here
    • also an option to find the biggest font size that fits within the text box
      • a max font size property would be useful here

I'm not very experienced with the library internals or C in general so for now I won't make a pull, I just want to throw the idea out there to the devs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing draw_multiline_text and getsize APIs and compare the linked script for current wrapping behavior. Clarify which width, height, clipping, and font-size behaviors are in scope before coding; done should be a defined text-box API with the selected behaviors covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.