Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否支持中文验证码,在captcha_config.json中配置中文验证码后,生成的验证码中,中文全是方框 #162

Open
150109514 opened this issue Sep 11, 2020 · 1 comment

Comments

@150109514
Copy link

150109514 commented Sep 11, 2020

我在使用"gen_sample_by_captcha.py"脚本生成中文验证码时,在sample/origin文件夹下生成的验证码图片中的中文全是方框。这个可有解决办法。captcha_config.json配置如下:
{
"root_dir": "sample/origin/",
"image_suffix": "png",
"characters": "你好中国我他她",
"count": 1000,
"char_count": 4,
"width": 100,
"height": 60
}

生成的验证码图片如下:
国他你国_1599784013988269

@150109514
Copy link
Author

150109514 commented Sep 11, 2020

问题解决了,是设置的字体问题。默认字体是:“DroidSansMono.ttf”,不支持中文。
在gen_sample_by_captcha.py中,初始化ImageCaptcha类的时候,可以设置字体。

fonts_path = 'xxxxx/Python36_64/lib/site-packages/captcha/data/'
fonts_list = [os.path.join(fonts_path, 'SIMYOU.ttf')]
generator = ImageCaptcha(width=width, height=height, fonts=fonts_list) #设置字体

生成的验证码图片如下:
你好_1599804422681344

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant