Pillow
Pillow copied to clipboard
Add ImageText.Text.wrap() to wrap text
Helps #6201
This adds a wrap() method to ImageText.Text. It will allow the user to wrap text within a certain width
from PIL import ImageText
text = ImageText.Text("Hello World!")
text.wrap(50)
print(text.text) # "Hello\nWorld!"
or within a certain width and height
text = ImageText.Text("Text does not fit within height")
print(text.wrap(50, 25).text == " within height") # May return a `ImageText.Text` instance
print(text.text) # "Text does\nnot fit"
or scaling, optionally with a font size limit.
text.wrap(50, 15, "shrink")
text.wrap(50, 15, ("shrink", 7))
text.wrap(58, 10, "grow")
text.wrap(50, 50, ("grow", 12))