修复验证码字体问题

This commit is contained in:
wzj 2025-06-14 19:37:51 +08:00
parent 61d9ba7db9
commit 1ad7b4f642
2 changed files with 6 additions and 3 deletions

9
app.py
View File

@ -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

Binary file not shown.