from PIL import Image, ImageFont, ImageDraw, ImageFilter
from random import choice, randint # 随即配置颜色
def rand_color():
return (randint(128, 255), randint(128, 255), randint(128, 255)) # 创建图片
# img = Image.new(格式,大小,颜色)
img = Image.new('RGB', (200, 50), 'white') # 创建字体
font = ImageFont.truetype('xdxwz.ttf', 30) # 创建画笔,画出img展示出的东西
draw = ImageDraw.Draw(img)
# 展示
# img.show()
code = ''.join(choice('0123456789') for i in range(4)) # 画字
for i in range(4):
# xy:位置, text:文本字, fill:颜色,font:字体
draw.text(xy=(i * 50 + 15, 0), text=code[i], fill='black', font=font) # 画干扰点
for i in range(200 * 50):
x = randint(0, 199)
y = randint(0, 49)
# xy:位置 , fill:颜色
draw.point(xy=(x, y), fill=rand_color())
#模糊处理,没啥事别加
# img = img.filter(ImageFilter.GaussianBlur)
img.show()
# 保存文本
img.save('{}.png'.format(code))
# 看一眼
print(code)

python制作验证码的更多相关文章

  1. 使用python制作验证码

    方法一 简单型:使用random模块制作一个随机字母与数字的验证码 import random def make_code(n): res='' for i in range(n): num=str( ...

  2. (一)学习MVC之制作验证码

    制作验证码的方法在@洞庭夕照 看到的,原文链接:http://www.cnblogs.com/mzwhj/archive/2012/10/22/2720089.html 现自己利用该方法制作一个简单的 ...

  3. 使用python制作ArcGIS插件(5)其他技巧

    使用python制作ArcGIS插件(5)其他技巧 by 李远祥 使用python做插件开发,除了了解ArcToolBox工具之外,还需要在了解ArcPy的相关函数和接口.只有掌握了这些,才可以顺利的 ...

  4. 使用python制作ArcGIS插件(4)界面交互

    使用python制作ArcGIS插件(4)界面交互 by 李远祥 插件界面部分,除了一开始在设计器中设计的这些界面元素之外,还可以与操作系统进行一些输入输出的交互,这部分的实现全部在pythonadd ...

  5. 使用python制作ArcGIS插件(3)ArcPy的使用说明

    使用python制作ArcGIS插件(3)ArcPy的使用说明 by 李远祥 ArcPy 是一个以成功的 arcgisscripting 模块为基础并继承了 arcgisscripting 功能进而构 ...

  6. 使用python制作ArcGIS插件(2)代码编写

    使用python制作ArcGIS插件(2)代码编写 by 李远祥 上一章节已经介绍了如何去搭建AddIn的界面,接下来要实现具体的功能,则到了具体的编程环节.由于使用的是python语言进行编程,则开 ...

  7. 使用python制作ArcGIS插件(1)工具介绍

    使用python制作ArcGIS插件(1)工具介绍 by 李远祥 ArcGIS从10.0开始支持addin(ArcGIS软件中又叫作加载项)的方式进行插件制作.相对于以往9.x系列,addin的无论是 ...

  8. python制作pdf电子书

    python制作pdf电子书 准备 制作电子书使用的是python的pdfkit这个库,pdfkit是 wkhtmltopdf 的Python封装包,因此在安装这个之前要安装wkhtmltopdf 安 ...

  9. Jsp制作验证码

    验证码 验证码(CAPTCHA)是"Completely Automated Public Turing test to tell Computers and Humans Apart&qu ...

随机推荐

  1. CentOS6.5(3)----设置自己安装的程序开机自动启动

    CentOS6.5系统下设置自己安装的程序开机自动启动 方法1. 把启动程序的命令添加到 /etc/rc.d/rc.local 文件中,比如设置开机启动 mysqld: #!/bin/sh # # T ...

  2. android.view.WindowLeaked的解决办法

    按字面了解,Window Leaked大概就是说一个窗体泄漏了,也就是我们常说的内存泄漏,为什么窗体会泄漏呢? 产生原因: 我们知道Android的每一个Activity都有个WindowManage ...

  3. Android深入四大组件(四)Android8.0 根Activity启动过程(前篇)

    前言 在几个月前我写了Android深入四大组件(一)应用程序启动过程(前篇)和Android深入四大组件(一)应用程序启动过程(后篇)这两篇文章,它们都是基于Android 7.0,当我开始阅读An ...

  4. 我的C语言连接Mysql之路

    1.安装好mysql     2.要实现C连接数据库,需要安装数据库连接器(即MySQL Connector/C)    MySQL Connector/C是一个C语言的client库,这个库是为了实 ...

  5. BigInteger方法总结

    BigInteger 可以用来解决数据的溢出问题. 下面我总结几种关于BigInteger的常用用法: 1.probablePrime和nextprobablePrime.(判断质数,并返回) Big ...

  6. oracle decode函数和 sign函数

    流程控制函数 DECODE decode()函数简介: 主要作用: 将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1, ...

  7. MySQL复制报错(Slave failed to initialize relay log info structure from the repository)

    机器重启以后,主从出现了问题,具体报错信息: Slave failed to initialize relay log info structure from the repository 解决方案: ...

  8. [翻译] HSDatePickerViewController

    HSDatePickerViewController HSDatePickerViewController is an iOS ViewController for date and time pic ...

  9. [翻译] CHAnimation

    CHAnimation https://github.com/cyndibaby905/CHAnimation How it looks CHAnimation is a project used t ...

  10. oracle 大表 已有大数据量 建索引防卡 nologging

    create index idx_th_user_info_fans_name on th_user_info(fans_name) nologging;