fix: use multiline_textbbox for image captcha

This commit is contained in:
Hsiaoming Yang
2023-07-29 12:19:11 +09:00
parent 35364f1981
commit 8c306694e5
2 changed files with 2 additions and 4 deletions

1
.gitignore vendored
View File

@@ -18,5 +18,6 @@ cover/
*.so
venv/
.venv/
demo.*
.coverage
coverage.xml

View File

@@ -103,10 +103,7 @@ class ImageCaptcha:
draw: ImageDraw,
color: ColorTuple) -> Image:
font = random.choice(self.truefonts)
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
_, _, w, h = draw.multiline_textbbox((1, 1), c, font=font)
dx1 = random.randint(0, 4)
dy1 = random.randint(0, 6)