python-pillow / python-pillow/Pillow
Automatic text wrapping/text box filling
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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