python-pillow / python-pillow/Pillow
ImageText.wrap() doesn't wrap text by width on height fit with shrink scaling
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13.8k
- Forks
- 2.5k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 89
Description
Code doesn't reach newline join
https://github.com/python-pillow/Pillow/blob/ec16a5785b89b277a027e5bc6203d15e6620c7e0/src/PIL/ImageText.py#L269-L270
Example:
width, height = 198, 228
text = "Master Librarian"
font = ImageFont.truetype("Courier.ttf", 30)
image_text = ImageText.Text(text, font)
image_text.stroke(width=0.7, fill="#ffffff")
a = image_text.wrap(width, height, scaling=("shrink", 20))
wrap = ImageText._Wrap(image_text, width, height, font)
print(repr(image_text.text), repr(a), repr(wrap.lines))
Outputs 'Master Librarian' None ['Master', 'Librarian']
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 in src/PIL/ImageText.py at the referenced wrap logic around lines 221-223 and the newline join around lines 269-270. Reproduce the provided example and compare wrap() with _Wrap.lines; done means height-fit shrink scaling returns the expected width-wrapped text instead of None.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100