Closed trepidacious closed 11 months ago
Can confirm the getbbox
works with Inky pHAT Red and pillow==10.1.0
.
Since:
getsize
was deprecated in 9.2.0 and end-of-life <10getbbox
was only made available from 9.2.0https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
Would the following help?
def getsize(font, text):
try:
# pillow>=9.2.0
# https://pillow.readthedocs.io/en/stable/releasenotes/9.2.0.html#font-size-and-offset-methods
_, _, right, bottom = font.getbbox(text)
return (right, bottom)
except AttributeError:
# Legacy fallback method
# pillow<10
return font.getsize(text)
Thank you!
Fix #175
font.getsize
can be replaced with a simple function calling through tofont.getbbox
. This seems to give very similar results, testing with a few quotes the size was almost always identical, sometimes different by 1 pixel.This allows the updated examples to work with Pillow 10.x