How to adjust font.getbbox
to use top to bottom as a text height
#8473
Answered
by
radarhere
AlexanderPodorov
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
Oct 17, 2024
Replies: 1 comment 1 reply
-
Does this suit your needs? from PIL import Image, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", size=48)
left, top, right, bottom = font.getbbox("Quick")
width, height = right - left, bottom - top
print(width, height) It prints a height of 35, which matches the height you expect from from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", size=48)
im = Image.new("RGB", (150, 50))
draw = ImageDraw.Draw(im)
draw.text((0, 0), "Quick", font=font)
im.save("out.png") |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
AlexanderPodorov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this suit your needs?
It prints a height of 35, which matches the height you expect from