fdivitto / FabGL

ESP32 Display Controller (VGA, PAL/NTSC Color Composite, SSD1306, ST7789, ILI9341), PS/2 Mouse and Keyboard Controller, Graphics Library, Sound Engine, Game Engine and ANSI/VT Terminal
http://www.fabglib.org
Other
1.48k stars 220 forks source link

Issue with ttf2header.py and Pillow 10.4.0 #400

Open BuslAV opened 1 month ago

BuslAV commented 1 month ago

Hello,

I encountered an issue while trying to use the ttf2header.py script from the FabGL project with Pillow version 10.4.0. Specifically, I get the following error:

AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

It seems that the getsize method was removed in newer versions of Pillow (starting from version 10.0.0). The recommended replacement is the textbbox method, which provides the bounding box of the text. By replacing the getsize call with textbbox, the issue is resolved.

Here’s an example fix:

bbox = f.getbbox(chr(i), stroke_width=stroke) w = bbox[2] - bbox[0] # Calculate width h = bbox[3] - bbox[1] # Calculate height

Would it be possible to update the script to support the latest versions of Pillow?

Thank you for your work on this project!

Best regards, Andrew