Skip to content

Add ImageText use_max_line_height()#9667

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

Add ImageText use_max_line_height()#9667
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:use_max_line_height

Conversation

@radarhere

Copy link
Copy Markdown
Member

Helps #1646. Alternative to #9581

Currently, the bottom of the bounding box of the text "A" is used to determine text line height.

#1646 found that other characters may have larger text height, leading to overlap between lines of text. While this is hard to see with most fonts, I found Great Vibes.

from PIL import Image, ImageDraw, ImageFont, ImageText
font = ImageFont.truetype("Tests/fonts/GreatVibes-Regular.ttf", 120)
text = ImageText.Text("adjust\nYellow", font)

im = Image.new("RGB", (309, 306))
draw = ImageDraw.Draw(im)
draw.text((0, 0), text, "#ff0")
im.save("before.png")

gives
before

This PR adds use_max_line_height() to ImageText. If I call that, the largest bounding box from all of the characters in the given text is used (not all possible characters of the font). Using that method, I get
after

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.

1 participant