From 3666104f20329bf5131754765fe972a11358ffa7 Mon Sep 17 00:00:00 2001 From: MrKeith99 Date: Mon, 22 Apr 2024 20:56:21 +0900 Subject: [PATCH 1/2] [FIX] textsize() was depricated, use textbbox() --- generator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generator.py b/generator.py index 5b89fa4..cd0bac5 100644 --- a/generator.py +++ b/generator.py @@ -158,11 +158,11 @@ def parse_objects(data): font = ImageFont.truetype("Arial.ttf", 30) # Calculate text size and position - text_size = draw.textsize(c, font) - if text_size[0] > img.size[0]: + _, _, text_width, text_height = draw.textbbox((0, 0), c, font=font) + if text_width > img.size[0]: font = ImageFont.truetype("Arial.ttf", 15) - text_size = draw.textsize(c, font) - text_position = ((img.size[0] - text_size[0]) // 2, img.size[1] - text_size[1] - 10) + _, _, text_width, text_height = draw.textbbox((0, 0), c, font=font) + text_position = ((img.size[0] - text_width) // 2, img.size[1] - text_height - 10) # Draw text on the image draw.text(text_position, c, font=font, fill="black") From 49db38ba1f1670a4dbefe38c74724c6f410c3045 Mon Sep 17 00:00:00 2001 From: MrKeith99 Date: Mon, 22 Apr 2024 20:58:06 +0900 Subject: [PATCH 2/2] [UPD] install Arial font for Linux users --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5f3d9e6..1c77097 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Instructions - `pip install qrcode[pil]` +- If using a Debian-based Linux operating systems: `sudo apt install ttf-mscorefonts-installer` - Execute `python generator.py` - Follow instructions \ No newline at end of file