Skip to content

When shrinking in ImageText wrap(), wrap text even if no scaling is required - #10025

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:imagetext
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:imagetext

Conversation

@radarhere

@radarhere radarhere commented Sep 18, 2026

Copy link
Copy Markdown
Member

Resolves #10024

In ImageText wrap(), when shrinking text, once the text is wrapped, if it fits into the space without any remaining text, then there is no shrinking required.

Pillow/src/PIL/ImageText.py

Lines 220 to 223 in 852d834

wrap = _Wrap(self, width, height, font)
if scaling == "shrink":
if not wrap.remaining_text:
return None

However, while that return statement avoided shrinking the font

Pillow/src/PIL/ImageText.py

Lines 225 to 233 in 852d834

size = math.ceil(font.size)
while wrap.remaining_text:
if size == max(limit, 1):
msg = "Text could not be scaled"
raise ValueError(msg)
size -= 1
font = self.font.font_variant(size=size)
wrap = _Wrap(self, width, height, font)
self.font = font

it also avoided applying the text wrapping.

self.text = newline.join(wrap.lines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageText.wrap() doesn't wrap text by width on height fit with shrink scaling

1 participant