Show me the code之Python练习册 Q10 生成验证码
2016-04-14 11:03
666 查看
""" 问题:使用 Python 生成类似于下图中的字母验证码图片 """ from PIL import Image, ImageFont, ImageDraw import random # 图片宽度 width = 100 # 图片高度 height = 40 def getcodeimg(): choiceCode = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C','D','E'] # 随机生成10个数字 code = [random.choice(choiceCode) for i in range(4)] print(' '.join(code)) image = Image.new('RGB', (width, height)) font = ImageFont.truetype('verdanaz.ttf', 20) draw = ImageDraw.Draw(image) draw.text((0, 0), ' '.join(code), font=font, fill='red') image.save('d://adfaf.png') if __name__ == '__main__': getcodeimg()
相关文章推荐
- Python一日一练16----折半查找
- Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理
- Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理
- Atitit. 注册表操作查询 修改 api与工具总结 java c# php js python 病毒木马的原理
- numpy学习笔记一:numpy的基本用法
- bs4抓起大众点评的用户评论
- python下配置matplotlib开发环境
- python批量给图加水印
- python 类属性
- 详解:Python2中的urllib、urllib2与Python3中的urllib以及第三方模块requests
- Python中*args 和**kwargs的用法
- Python之sys模块
- Python模块之os.path
- 初学python(对比java语言不同) 第十篇
- 人脸检测新手入门篇
- python爬虫入门实践
- python线程的一些疑问
- Python教程1-7
- python非阻塞启动进程
- python 小模块--platform