From e3710ea00a9cf9dd3cde066eb27243bd7fcd4be7 Mon Sep 17 00:00:00 2001 From: Hsiaoming Yang Date: Sat, 29 Jul 2023 10:29:01 +0900 Subject: [PATCH] fix: use the code provided by @ThiefMaster https://github.com/lepture/captcha/issues/63 --- src/captcha/image.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/captcha/image.py b/src/captcha/image.py index ecc43f7..84de254 100644 --- a/src/captcha/image.py +++ b/src/captcha/image.py @@ -103,7 +103,10 @@ class ImageCaptcha: draw: ImageDraw, color: ColorTuple) -> Image: font = random.choice(self.truefonts) - _, _, w, h = draw.textbbox((1, 1), c, font=font) + + left, top, right, bottom = draw.textbbox((0, 0), c, font=font) + w = int((right - left)*1.7) or 1 + h = int((bottom - top)*1.7) or 1 dx1 = random.randint(0, 4) dy1 = random.randint(0, 6)