利用captcha库绘制验证码
#导包
from captcha.image import ImageCaptcha
from PIL import Image
import random
import time
import os #定义随机方法
def random_captcha():
#定义一个容器
captcha_text = []
for i in range(4):
#定义验证码字符
c = random.choice(['','','','',''])
captcha_text.append(c)
#返回一个随机生成的字符串
return ''.join(captcha_text) #生成验证码方法
def gen_captcha():
#定义图片对象
image = ImageCaptcha()
#获取字符串
captcha_text = random_captcha()
#生成图像
captcha_image = Image.open(image.generate(captcha_text))
return captcha_text,captcha_image if __name__ == "__main__":
#定义图片个数
count = 1
#定义图片文件夹
path = './captcha_image'
#如果没有就创建
if not os.path.exists(path):
os.makedirs(path)
#循环创建图片
for i in range(count):
#定义创建时间
now = str(int(time.time()))
#接收字符串和图片
text,image = gen_captcha()
#定义图片名称
filename = text + "_" + now + ".png"
#存储图片
image.save(path + os.path.sep + filename)
print('saved %s' %filename)
利用captcha库绘制验证码的更多相关文章
- 利用 turtle库绘制简单图形
turtle库是python的基础绘图库,这个库被介绍为一个最常用的用来介绍编程知识的方法库,其主要是用于程序设计入门,是标准库之一,利用turtle可以制作很多复杂的绘图. turtle名称含义为“ ...
- python 利用turtle库绘制七段数码管的方式,绘制当前事件(时分秒00:00:00)
# coding:utf-8# 绘制七段数码管,显示当前时间import timeimport turtle as tt # 绘制间隔def drawGap(): tt.penup() tt.fd(3 ...
- python 利用turtle库绘制五角星
# -*- coding: utf-8 –*-import turtleimport math def draw_polygon(aTurtle, size=50, n=3): for i in ra ...
- captcha库报错"OSError: cannot open resource"
问题描述 在win平台上python虚拟环境下使用captcha库生成验证码报错OSError: cannot open resource 代码 from captcha.image import I ...
- Python turtle库绘制简单图形
一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...
- python利用selenium库识别点触验证码
利用selenium库和超级鹰识别点触验证码(学习于静谧大大的书,想自己整理一下思路) 一.超级鹰注册:超级鹰入口 1.首先注册一个超级鹰账号,然后在超级鹰免费测试地方可以关注公众号,领取1000积分 ...
- php学习笔记:利用gd库生成图片,并实现随机验证码
说明:一些基本的代码我都进行了注释,这里实现的验证码位数.需要用的字符串都可以再设置.有我的注释,大家应该很容易能看得懂. 基本思路: 1.用mt_rand()随机生成数字确定需要获取的字符串,对字符 ...
- 利用GDI+在Winfrom绘制验证码
string yzm: private void yangzhengma() { Bitmap bt = new Bitmap(70,22);//创建位图对象 Graphics gs = Graphi ...
- php 简单的学习GD库绘制图片并传回给前端实现方式
1.基本的GD库绘制图片汇总 2.后台实现小案例 <?php // $img = imagecreatetruecolor(200,40); // var_dump($img); // 利用GD ...
随机推荐
- Python cmd库的简易使用
简单记录一下,竟然这么简单的方法就能在 python 里面实现一个简单的交互式命令行以前从来没有尝试过. 上一个完整的例子: import cmd import osimport readline r ...
- Linux下 rewrite_mod 的配置
以下使用最新的 Ubuntu 16.04 测试; 安装好apache后先确认有没有rewrite模块,大多数情况下是有的:ls /etc/apache2/mods-available |grep re ...
- Python学习之路—————day04
今日内容: 1. 循环语句 1.1 if判断 1.2 while循环 1.3 for循环 一.if判断 语法一: if 条件 代码块1 代码块2 代码块3 # 例: sex='female' age= ...
- How to mount EFI on macOS
mount -t msdos /dev/disk0s1 /volumes/efi
- UVA 690 Pipeline Scheduling
https://vjudge.net/problem/UVA-690 题目 你有一台包含5个工作单元的计算机,还有10个完全相同的程序需要执行.每个程序需要$n(n<20)$个时间片来执行,可以 ...
- Nginx用户权限验证管理
首先需要编译进--with-http_request_model 配置指令:auth_request url | off; #url是指上游服务器地址 context: http/location 备 ...
- 【RNN】资源汇总
wesome Recurrent Neural Networks A curated list of resources dedicated to recurrent neural networks ...
- Git秘钥生成以及Gitlab配置
安装Git:详见http://www.cnblogs.com/xiuxingzhe/p/9300905.html 开通gitlab(开通需要咨询所在公司的gitlab管理员)账号后,本地Git仓库和g ...
- spring boot项目基本结构
/==================================Controller @Controller public class SimpleController { @Autowired ...
- BZOJ4873[Shoi2017]寿司餐厅——最大权闭合子图
题目描述 Kiana最近喜欢到一家非常美味的寿司餐厅用餐.每天晚上,这家餐厅都会按顺序提供n种寿司,第i种寿司有一个 代号ai和美味度di,i,不同种类的寿司有可能使用相同的代号.每种寿司的份数都是无 ...