from PIL import Image,ImageDraw,ImageFont
import random
from io import BytesIO class code():
def __init__(self):
self.codelen=4
self.codeCon="ABCDEFG23456789acbdsvjhn"
self.width=120
self.height=60
self.im=None
self.lineNum=0
self.pointNum=0
def randBgColor(self):
return (random.randint(0,120),random.randint(0,120),random.randint(0,120),220)
def create(self):
self.bg=self.randBgColor()
self.im=Image.new("RGBA",size=(self.width,self.height),color=self.bg)
def randFgColor(self):
return (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255),255)
def lines(self):
lineNum=self.lineNum or random.randint(5,10)
draw = ImageDraw.Draw(self.im)
for itenm in range(lineNum):
place=(random.randint(0,self.width),random.randint(0,self.height),random.randint(0,self.width),random.randint(0,self.height))
draw.line(place,fill=self.randFgColor(),width=random.randint(1,2))
def point(self):
pointNum = self.pointNum or random.randint(20, 60)
draw = ImageDraw.Draw(self.im)
for itenm in range(pointNum):
place = (random.randint(0, self.width), random.randint(0, self.height))
draw.point(place, fill=self.randFgColor())
def rote(self):
self.im=self.im.rotate(random.randint(-10,20))
im1=Image.new("RGBA",size=(self.width,self.height),color=self.bg)
self.im=Image.composite(self.im,im1,self.im)
def text(self):
draw = ImageDraw.Draw(self.im)
for item in range(self.codelen):
self.codeCon[random.randint(0,len(self.codeCon)-1)]
text=self.codeCon[random.randint(0,len(self.codeCon)-1)]
draw.text((item*self.width/self.codelen,random.randint(0,self.height-40)),text,fill=self.randFgColor(),font=ImageFont.truetype("C:/Windows/Fonts/AdobeSongStd-Light.otf",random.randint(26,50)))
self.rote()
def output(self):
self.create()
self.lines()
self.point()
self.text()
self.im.show()
# self.im.save("11.png","png")
bt=BytesIO()
self.im.save(bt,"png") #保存内存
return bt.getvalue() codeobj=code()
codeobj.output()

python图形图像处理--验证码的制作的更多相关文章

  1. 实验:Python图形图像处理

    1. 准备一张照片,编写Python程序将该照片进行图像处理,分别输出以下效果的图片:(a)灰度图:(b)轮廓图: (c)变换RGB通道图:(d)旋转45度图. 2. 假设当前文件夹中data.csv ...

  2. Python图形图像处理库的介绍之Image模块

    http://onlypython.group.iteye.com/group/wiki/1372-python-graphics-image-processing-library-introduce ...

  3. python PIL 图像处理

    python PIL 图像处理 This blog is from: https://www.jianshu.com/p/e8d058767dfa Image读出来的是PIL的类型,而skimage. ...

  4. python之使用PIL模块制作随机验证码

    制作随机验证码,需要如下知识点: 1.随机验证码的制作(这里用的是random模块随机产生字符) 2.图片的制作 3.随机直线干扰项 4.其他随机干扰项 代码如下: from PIL import I ...

  5. C&C++图形图像处理开源库

    Google三维APIO3D O3D 是一个开源的 WebAPI 用来在浏览器上创建界面丰富的交互式的 3D 应用程序.这是一种基于网页的可控3D标准.此格式期望真正的基于浏览器,独立于操作系统之外, ...

  6. Python 代码实现验证码识别

    Python 代码实现验证码识别 测试开发社区  1周前 源 /  j_hao104 一.探讨 识别图形验证码可以说是做爬虫的必修课,涉及到计算机图形学,机器学习,机器视觉,人工智能等等高深领域…… ...

  7. python数字图像处理(17):边缘与轮廓

    在前面的python数字图像处理(10):图像简单滤波 中,我们已经讲解了很多算子用来检测边缘,其中用得最多的canny算子边缘检测. 本篇我们讲解一些其它方法来检测轮廓. 1.查找轮廓(find_c ...

  8. Python识别网站验证码

    http://drops.wooyun.org/tips/6313 Python识别网站验证码 Manning · 2015/05/28 10:57 0x00 识别涉及技术 验证码识别涉及很多方面的内 ...

  9. python PIL 图像处理操作

    python PIL 图像处理 # 导入Image库 import Image # 读取图片 im = Image.open("1234.jpg") # 显示图片 im.show( ...

随机推荐

  1. 快速排序和二分查找(Java)

    import java.util.Arrays; public class Main { public static void main(String[] args) { int[] data = { ...

  2. spring boot 常用注解

    @RestController和@RequestMapping注解 4.0重要的一个新的改进是@RestController注解,它继承自@Controller注解.4.0之前的版本,spring M ...

  3. [C#菜鸟]C# Hook (二) 常用钩子的类型

    ; //监视和记录输入事件.安装一个挂钩处理过程,对寄送至系统消息队列的输入消息进行纪录 ; //回放用WH_JOURNALRECORD记录事件 ; //键盘钩子,键盘触发消息.WM_KEYUP或WM ...

  4. BeanDefinition 实例

    BeanDefinition BeanDefinition /** * BeanDefinition 用于描述一个 bean 实例,包括属性值.构造参数和补充信息. */ public interfa ...

  5. JS - neo4j-browser 初始化时运行命令的逻辑分析

    背景 最近需要改点 neo4j-browser 的代码做个 demo,分析初始化时运行命令的代码时花了很多时间,记录一下. 目的 找出 dispatch SINGLE_COMMAND_QUEUED a ...

  6. mysql--创建表,插入数据,修改表名,删除表,简单查询/内连接、左/右连接

    创建表mm:  其中id为主键且自增长 ) primary key not null unique auto_increment, name ) not null, age ), class ) no ...

  7. Idea创建项目后,提交项目到码云的问题

    1.创建git仓库:vcs->import int version control->Create git repository 2.在项目头点击右键->git->add 3. ...

  8. Oracle 笔记(一)

    Oracle基本理论 l  主流数据库 微软公司:SQL Server  ACCESS IBM公司:DB2  infomix Oracle公司:Oracle  MySQL(AB公司) 小型数据库 AC ...

  9. MYSQL5.5 linux安装

    1.常规的编译安装MYSQL 此种方法使用所有Mysql5.0 - 5.1 系列产品 比较常规的编译方式 2. 采用cmake 方式编译安装Mysql 3.二进制安装方式 免编译安装MYSQL 4.如 ...

  10. js脚本实现在该界面直接跳转到一个登录界面并且自动登录

    1:首先说明的是自动登录也是需要密码的,这是前一个网页传输过去的 2:这里我使用的是post提交表单的形式 <------------------------------------------ ...