Skip to content

Commit ccc75a4

Browse files
committed
chore:调整图片比例
1 parent ba93fd2 commit ccc75a4

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

app/util/captcha.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import io
33
import random
44
import string
5+
from typing import Tuple
56

67
from PIL import Image, ImageDraw, ImageFont
78

@@ -33,7 +34,7 @@ def draw_lines(self, num=3):
3334
y2 = random.randint(self.height / 2, self.height)
3435
self.draw.line(((x1, y1), (x2, y2)), fill="black", width=1)
3536

36-
def get_verify_code(self):
37+
def get_verify_code(self) -> Tuple[bytes, str]:
3738
"""
3839
生成验证码图形
3940
"""
@@ -54,9 +55,9 @@ def get_verify_code(self):
5455
# 划线
5556
# self.draw_lines()
5657
# 重新设置图片大小
57-
self.im = self.im.resize((100, 24))
58+
self.im = self.im.resize((80, 30))
5859
# 图片转为base64字符串
5960
buffered = io.BytesIO()
60-
self.im.save(buffered, format="JPEG")
61-
img_str = b"data:image/png;base64," + base64.b64encode(buffered.getvalue())
62-
return img_str, code
61+
self.im.save(buffered, format="webp")
62+
img = b"data:image/png;base64," + base64.b64encode(buffered.getvalue())
63+
return img, code

0 commit comments

Comments
 (0)