fix: 使用容器内可用字体生成验证码

尝试多个字体路径,优先使用Liberation字体

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-11 22:52:39 +08:00
parent 87b04e84d3
commit fc9c264f37

16
app.py
View File

@@ -1065,9 +1065,19 @@ def generate_captcha():
draw.point((x, y), fill=(random.randint(0, 200), random.randint(0, 200), random.randint(0, 200)))
# 绘制验证码文字 - 增大字体
try:
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 42)
except:
font = None
font_paths = [
"/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf",
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
"/usr/share/fonts/truetype/freefont/FreeSansBold.ttf",
]
for font_path in font_paths:
try:
font = ImageFont.truetype(font_path, 42)
break
except:
continue
if font is None:
font = ImageFont.load_default()
for i, char in enumerate(code):