python图形图像处理--验证码的制作
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图形图像处理--验证码的制作的更多相关文章
- 实验:Python图形图像处理
1. 准备一张照片,编写Python程序将该照片进行图像处理,分别输出以下效果的图片:(a)灰度图:(b)轮廓图: (c)变换RGB通道图:(d)旋转45度图. 2. 假设当前文件夹中data.csv ...
- Python图形图像处理库的介绍之Image模块
http://onlypython.group.iteye.com/group/wiki/1372-python-graphics-image-processing-library-introduce ...
- python PIL 图像处理
python PIL 图像处理 This blog is from: https://www.jianshu.com/p/e8d058767dfa Image读出来的是PIL的类型,而skimage. ...
- python之使用PIL模块制作随机验证码
制作随机验证码,需要如下知识点: 1.随机验证码的制作(这里用的是random模块随机产生字符) 2.图片的制作 3.随机直线干扰项 4.其他随机干扰项 代码如下: from PIL import I ...
- C&C++图形图像处理开源库
Google三维APIO3D O3D 是一个开源的 WebAPI 用来在浏览器上创建界面丰富的交互式的 3D 应用程序.这是一种基于网页的可控3D标准.此格式期望真正的基于浏览器,独立于操作系统之外, ...
- Python 代码实现验证码识别
Python 代码实现验证码识别 测试开发社区 1周前 源 / j_hao104 一.探讨 识别图形验证码可以说是做爬虫的必修课,涉及到计算机图形学,机器学习,机器视觉,人工智能等等高深领域…… ...
- python数字图像处理(17):边缘与轮廓
在前面的python数字图像处理(10):图像简单滤波 中,我们已经讲解了很多算子用来检测边缘,其中用得最多的canny算子边缘检测. 本篇我们讲解一些其它方法来检测轮廓. 1.查找轮廓(find_c ...
- Python识别网站验证码
http://drops.wooyun.org/tips/6313 Python识别网站验证码 Manning · 2015/05/28 10:57 0x00 识别涉及技术 验证码识别涉及很多方面的内 ...
- python PIL 图像处理操作
python PIL 图像处理 # 导入Image库 import Image # 读取图片 im = Image.open("1234.jpg") # 显示图片 im.show( ...
随机推荐
- Demo:servlet实现图片的上传
一个简单的servlet例子,实现图片的上传功能,上传的图片给 ?HttpServletResponse 对象 public class BackGroundLogoServlet extends H ...
- mongo注解详解
1.@Entity如果你想通过Morphia把你的对象保存到Mongo中,你首先要做的是使用@Entity注解你的类:@Entity(value="comm_user_favorite_co ...
- maven 配置国内镜像仓库加速获取jar包的配置方法
在 maven 的 conf/settings.xml 中配置 <mirrors> <!-- mirror | Specifies a repository mirror site ...
- 一、基础篇--1.2Java集合-List、Set、Map区别
List.Set.Map区别 三者关系如下: 结构特点 1.List和Set是存储单列数据集合,Map是存储键值对这样的双列数据集合: 2.List中存储的数据都是有序的,并且允许重复:Map中存储 ...
- 解决:linux eclipse 对‘dlopen’未定义的引用, 对‘xxx’未定义的引用
如果是终端窗口执行的话直接: 在g++编译选项后面,加入dl的库,选项为-ldl,即可. 如果是在eclipse里的话: 在工程属性中->c/c++ build->gcc complier ...
- [常用的SQL语句总结]
1. 创建数据库DataBase create database 数据库名称; 2. 删除数据库DataBase drop database 数据库名称 drop database 数据库名称1, ...
- linux添加新用户
使用root用户adduser yj 后面操作有提示 用这种方法新建的用户会在home下生成用户文件夹
- 集成ShareSdk一键分享和第三方登录
在Mob官网http://mob.com/注册,创建应用,下载SDK,申请APP_key 根据官网开发指南导入SDK到你的项目中: 在assets/ShareSDk.xml中修改你的APP_key p ...
- Windows 10下怎么远程连接 Ubuntu 16.0.4(方案二)
使用TeamViewer实现远程桌面连接 背景: 有些朋友反映,借助Ubuntu自带的桌面共享工具desktop sharing会有不再同一网端下出现连接不稳定或者掉线的问题,那么现在我们就可以借助第 ...
- unittest 和 pytest 对比
一.用例编写规则 1.unittest提供了test cases.test suites.test fixtures.test runner相关的类,让测试更加明确.方便.可控.使用unittest编 ...