Skip to content

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

Description

@Dezzelshipc

Pillow/src/PIL/ImageText.py

Lines 221 to 223 in ec16a57

if scaling == "shrink":
if not wrap.remaining_text:
return None

Code doesn't reach newline join

Pillow/src/PIL/ImageText.py

Lines 269 to 270 in ec16a57

newline = "\n" if isinstance(self.text, str) else b"\n"
self.text = newline.join(wrap.lines)

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']

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions