生成验证码图片(三)

来源:互联网 发布:网络行为管理软件 编辑:程序博客网 时间:2024/05/24 00:09

地址:http://blog.csdn.net/u011463646/article/details/77142028

利用第三方库

'''Created on 2017-7-19@author: XTing'''from io import BytesIOfrom captcha.audio import AudioCaptchafrom captcha.image import ImageCaptchafrom PIL import Imageimport numpy as npimport matplotlib.pyplot as plt# audio = AudioCaptcha(voicedir='/path/to/voices')image = ImageCaptcha(fonts=['./font/platech.ttf', './font/platechar.ttf'])# data = audio.generate('1234')# assert isinstance(data, bytearray)# audio.write('1234', 'out.wav')text = '1234'Save_Path = './captcha_picture/out.jpg'# data = image.generate(text)# assert isinstance(data, BytesIO)image.write(text, Save_Path)#to savecaptcha_image = Image.open(Save_Path)captcha_image = np.array(captcha_image)#show imagef = plt.figure()plt.imshow(captcha_image)plt.show(f)

效果

这里写图片描述

原创粉丝点击