用 python 写验证码的例子
来源:互联网 发布:no热力学数据 编辑:程序博客网 时间:2024/05/01 07:13
import Image, ImageDraw, ImageFont, ImageFilterimport random#letterdef rndChar(): return chr(random.randint(65, 90))# color1def rndColor(): return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255))# color2:def rndColor2(): return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))# 240 x 60:width = 60 * 4height = 60image = Image.new('RGB', (width, height), (255, 255, 255))# make Font object:font = ImageFont.truetype('Arial.ttf', 36)# make Draw object:draw = ImageDraw.Draw(image)# fill pixelsfor x in range(width): for y in range(height): draw.point((x, y), fill=rndColor())# print letterfor t in range(4):#the show letter is 4 draw.text((60 * t + 10, 10), rndChar(), font=font, fill=rndColor2())# blurimage = image.filter(ImageFilter.BLUR)image.save('code.jpg', 'jpeg');image.show()
#后添加汉子会出现报错如下:
but no encoding declared see http //python.org/dev/peps/pep-0263/ for details
解决方案:把#后面的数字变为英文就可以了。
for t in range(4):#the show letter is 4 draw.text((60 * t + 10, 10), rndChar(), font=font, fill=rndColor2())这个一部分是字体的显示,提供了一个循环显示的例子。
0 0
- 用 python 写验证码的例子
- [转载]用servlet写的一个验证码的例子
- 用python写的fitnesse ActionFixture例子
- 用python写的fitnesse DoFixture例子
- 用Python ZSI写web service的简单例子
- 关于Python写一个简单的验证码图片
- 学习python--写的copyfile例子
- 自己写的python学习例子
- Python写的贪吃蛇游戏例子
- 用Python写了一个验证码识别
- 用php写的验证码
- 用java写的验证码程序
- 用java写的验证码
- 用PHP写的验证码
- 验证码的简单例子
- 验证码倒计时的例子
- 简单的写验证码
- flex写的验证码
- My97DatePicker时间控件使用
- android Configuration详解
- Promise系列02:Promise创建
- ffmpeg 继续学习 -- ARM优化-- AArch64
- 二、linux vi编辑常用命令
- 用 python 写验证码的例子
- .Net运行环境问题,3.5无法很好的运行在4.0下
- 组合与聚合
- redis中各种数据类型对应的jedis操作命令
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- PHP学习-数据库连接
- Servlet中的过滤器Filter详解
- Error:Cause: com.android.sdklib.repository.FullRevision
- Volley的网络请求有内存溢出现象