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 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")