heuer / segno

Python QR Code and Micro QR Code encoder
https://pypi.org/project/segno/
BSD 3-Clause "New" or "Revised" License
606 stars 52 forks source link

Fix for pillow 10 #128

Closed gene-git closed 11 months ago

gene-git commented 11 months ago

The file examples/qrcode_text/png_text.py Fails with missing method:


    fw, fh = font.getsize(line)
             ^^^^^^^^^^^^
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

This patch fixes it.

--- a/png_text.py   2023-10-17 12:33:47.469268721 -0400
+++ b/png_text.py   2023-10-17 12:34:17.220677606 -0400
@@ -89,7 +89,9 @@
     lines = text.splitlines()
     # Calculate the additional space required for the text
     for line in lines:
-        fw, fh = font.getsize(line)
+        (left, top, right, bottom) = font.getbbox(line)
+        fw = right - left
+        fh = bottom - top
         if fw > width:
             width = fw + font_size
         height += fh + line_spacing