修复验证码字体问题
This commit is contained in:
parent
61d9ba7db9
commit
1ad7b4f642
9
app.py
9
app.py
@ -77,9 +77,12 @@ def generate_captcha_image():
|
||||
|
||||
# 尝试加载字体,失败则使用默认字体
|
||||
try:
|
||||
font = ImageFont.truetype("arial.ttf", 24)
|
||||
except:
|
||||
font = ImageFont.load_default()
|
||||
# 指定字体路径(假设字体文件是 static/arial.ttf)
|
||||
font_path = os.path.join(current_app.static_folder, "arial.ttf")
|
||||
font = ImageFont.truetype(font_path, 24)
|
||||
except Exception as e:
|
||||
print(f"加载字体失败: {e}")
|
||||
font = ImageFont.load_default() # 回退到默认字体
|
||||
|
||||
# 绘制验证码文本(每个字符随机颜色)
|
||||
for i, char in enumerate(captcha_code):
|
||||
|
||||
BIN
static/arial.ttf
Normal file
BIN
static/arial.ttf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user