使用 Python 生成驗(yàn)證碼
使用Python的captcha 的庫(kù),我們將非常簡(jiǎn)單的使用Python高級(jí)函數(shù)來生成驗(yàn)證碼。
1、安裝驗(yàn)證碼 captcha 庫(kù)
pip install captcha
2、然后使用
(1)、使用 create_captcha_image 函數(shù)生成驗(yàn)證碼。通過此功能,您可以設(shè)置文本、字體顏色和背景顏色。
from captcha.image import ImageCaptcha captcha = ImageCaptcha() captcha = captcha.create_captcha_image('123', 'red', 'white') captcha.save('test.jpg')
結(jié)果:
(2)、使用effect_spread函數(shù) 添加一些距離來擴(kuò)散像素。
from captcha.image import ImageCaptcha captcha = ImageCaptcha() captcha = captcha.create_captcha_image('123', 'red', 'white') captcha = captcha.effect_spread(6) captcha.save('test.jpg')
結(jié)果:
(3)、使用旋轉(zhuǎn)功能 旋轉(zhuǎn)驗(yàn)證碼
from captcha.image import ImageCapt chacaptcha = ImageCaptcha() captcha = captcha.create_captcha_image('123', 'red', 'white') captcha = captcha.rotate(angle= 50, expand=True) captcha.save('test.jpg')
結(jié)果:
文章來源:http://www.zghlxwxcb.cn/article/302.html
以上就是使用Python的庫(kù),非常簡(jiǎn)單生成驗(yàn)證碼。文章來源地址http://www.zghlxwxcb.cn/article/302.html
到此這篇關(guān)于使用 Python 生成驗(yàn)證碼的高級(jí)方法的文章就介紹到這了,更多相關(guān)內(nèi)容可以在右上角搜索或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!