最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
整理Python生成随机中文图片验证码源代码
时间:2015-01-15 编辑:简简单单 来源:一聚教程网
在登录很多网站的时候,他们已经不在使用简单的英文和数字的验证码,为了防止恶心注册和群发软件的侵袭,现在都开始使用中文的验证码了。
今天我们就跟大家分享一段用Python生成随机的中文验证码图片源代码。
代码如下 | 复制代码 |
# -*- coding: utf-8 -*- class RandomChar(): @staticmethod class ImageChar(): def rotate(self): def drawText(self, pos, txt, fill): def randRGB(self): def randPoint(self): def randLine(self, num): def randChinese(self, num): def save(self, path): |
python生成验证码(webpy完整验证码类)
python生成验证码可以使用成熟的wheezy.captcha,首先需要安装PIL包 easy_install PIL, 然后需要安装wheezy.captcha easy_install wheezy.captcha
安装之后生成验证码就很简单了:
代码如下 | 复制代码 |
captcha_image_t = captcha(drawings=[ image_t = captcha_image_t(chars_t) |
验证码效果图如下:
验证码captcha
完整的webpy生成验证码类实现如下:
代码如下 | 复制代码 |
#!/usr/bin/env python __author__ = 'outofmemory.cn' from wheezy.captcha.image import captcha from wheezy.captcha.image import background from wheezy.captcha.image import offset import random from os import path if __name__ == '__main__': from run import session _controllersDir = path.abspath(path.dirname(__file__)) _chars = 'ABCDEFJHJKLMNPQRSTUVWXY3456789' SESSION_KEY_CAPTCHA = 'captcha' def isValidCaptcha(captchaInputName='captcha'): class Captcha: def GET(self): if __name__ == '__main__': image_t = captcha_image_t(chars_t) |
程序中使用的字体文件要放在web目录同级的fonts目录下,程序中的两个字体文件都是复制的windows字体,在linux下可以正常使用,要注意扩展名的大小写。
-
上一个: Yii2.0 批量插入数据的几种方法
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24