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( ...
随机推荐
- Scrum立会报告+燃尽图 02
本次作业要求参见:https://edu.cnblogs.com/campus/nenu/2019fall/homework/9912 一.小组情况组长:贺敬文组员:彭思雨 王志文 位军营 徐丽君队名 ...
- JDBC连接数据库遇到的“驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。
要从旧算法列表中删除3DES: 在JDK 8及更早版本中,编辑该 /lib/security/java.security文件并3DES_EDE_CBC从jdk.tls.legacyAlgorithms ...
- spark 笔记 4:Apache Hadoop YARN: Yet Another Resource Negotiator
spark支持YARN做资源调度器,所以YARN的原理还是应该知道的:http://www.socc2013.org/home/program/a5-vavilapalli.pdf 但总体来说, ...
- RF Setup和Teardown的使用
执行顺序 setup执行顺序是:project级别setup>suite级别setup>case级别setup 无返回值 Run Keywords | [KW1 | arg1 | arg2 ...
- Vue路由器的简单实现
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Android Studio设置国内镜像代理
点击主面板右下角的Configure –> settings –> Appearance & Behavior –> System Settings –> HTTP P ...
- 浏览器端-W3School-HTML:HTML DOM Object 对象
ylbtech-浏览器端-W3School-HTML:HTML DOM Object 对象 1.返回顶部 1. HTML DOM Object 对象 Object 对象 Object 对象代表 HTM ...
- Http常见的响应头
Location: http://www.it315.org/index.jsp -表示重定向的地址,该头和302的状态码一起使用. Server:apache tomcat ...
- CSS 有序或者无序列表的前面的标记 list-style-type 属性
例子: <html> <head> <style type="text/css"> ul.none{list-style-type:none} ...
- docker扩容
方法一. https://www.cnblogs.com/atuotuo/p/7217331.html 只需要修改 dockerd 的启动参数啊 增加 --data-root 把 /var/lib/d ...