Automatic text wrapping/text box filling

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #9639 by @RichardHopperProGrammar — closed without merging

Assessment

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

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.

Description

Enhancement

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

Dominant language
Python
Stars
14k
Forks
2.6k
Avg merge
1d 1h
Merged PRs (30d)
205

Getting set up

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.

More from python-pillow/Pillow

All issues in python-pillow/Pillow

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.