pillow生成验证码
1、结果
2、安装pillow
cmd里进入python,pip install pillow,需要等一段时间
3、代码
from PIL import Image, ImageDraw, ImageFont, ImageFilter import random # 随机字母:
def rndChar():
return chr(random.randint(65, 90)) # 随机颜色1:
def rndColor():
return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255)) # 随机颜色2:
def rndColor2():
return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127)) # 240 x 60:
width = 60 * 4
height = 60
image = Image.new('RGB', (width, height), (255, 255, 255))
# 创建Font对象:
font = ImageFont.truetype(r'C:\Windows\Fonts\Arial.ttf', 36)
# 创建Draw对象:
draw = ImageDraw.Draw(image)
# 填充每个像素:
for x in range(width):
for y in range(height):
draw.point((x, y), fill=rndColor())
# 输出文字:
for t in range(4):
draw.text((60 * t + 10, 10), rndChar(), font=font, fill=rndColor2())
# 模糊:
image = image.filter(ImageFilter.BLUR)
image.save("C:\\Users\\rainbow\\Desktop\\1.jpg", 'jpeg')
print("create ok")
pillow生成验证码的更多相关文章
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
最近在用Python开发自己的博客,需要用到Python生成验证码,当然肯定要用到Python的图形处理库PIL,因为我用的是windows. 所以在安装好pil之后就开始写,就按照题目所说出现了Th ...
- python3用pillow生成验证码,tornado中输出图片
原文链接http://blog.csdn.net/cdnight/article/details/49636893
- Python 使用Pillow模块生成验证码
1.安装 pip3 install pillow 2.使用步骤 生成验证码和验证字符串 绘制图片,将验证码放入session中 将图片返回给页面 3.代码demo #!/usr/bin/env pyt ...
- Django 生成验证码或二维码 pillow模块
一.安装PIL PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,API也非常简单易用. PIL模块只支持到Python 2 ...
- 第二百七十节,Tornado框架-生成验证码图片,以及验证码结合Session验证
Tornado框架-生成验证码图片,以及验证码结合Session验证 第一.生成验证码图片 生成验证码图片需要两个必须模块 1.python自带的random(随机模块) 2.Pillow()图像处 ...
- 动态生成验证码———MVC版
上面有篇博客也是写的验证码,但那个是适用于asp.net网站的. 今天想在MVC中实现验证码功能,弄了好久,最后还是看博友文章解决的,感谢那位博友. 首先引入生成验证码帮助类. ValidateCod ...
- laravel 生成验证码的方法
在Laravel中有很多图片验证码的库可以使用,本篇介绍其中之一:gregwar/captcha,这个库比较简单,在Laravel中比较常用.下面我们就来介绍下使用细节: 首先, composer.j ...
- java web学习总结(九) -------------------通过Servlet生成验证码图片
一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下:
- android 生成验证码图片
(转自:http://blog.csdn.net/onlyonecoder/article/details/8231373) package com.nobeg.util; import java.u ...
随机推荐
- C#会对于未赋值的变量/成员变量,给予一个初始值吗?
如果我有程序如下: C# code ? 1 2 3 4 5 6 7 public class My { public bool b; public ...
- Web界面进行用户管理
Web界面进行用户管理 添加用户 Tags:表示账号的角色 Admin:超级管理员 No access :表示没有可以访问的virtual host虚拟机(相当于数据库) ...
- Rpgmakermv(24 )yep_coreengine
==左部为原文,右边我做了简要翻译=================================== Introduction and Instructions ================= ...
- .NET Core Tools for Visual Studio 2015 安装失败
You may be blocked from installing the .NET Core Tooling Preview 2 for Visual Studio 2015 installer ...
- html5-移动端布局模板
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- JavaScript 基础,登录验证
1.<script></script>的三种用法: a.放在<body>中 b.放在<head>中 c.放在外部JS文件中 <!DOCTYPE h ...
- wrapper class (Integer 为例)
1,导入 Integer a = 100; Integer b = 100; Integer c = 150; Integer d = 150; a == b; true c == d; false ...
- Knowing is not enough; we must apply. Willing is not enough; we must do.
Knowing is not enough; we must apply. Willing is not enough; we must do. 仅限于知道是不够的,我们必须去实践:单纯的希望是不够的 ...
- python range函数
这个函数很简单,就不写例子了,看看语法,拿来即用 python range() 函数可创建一个整数列表,一般用在 for 循环中. 函数语法 range(start, stop[, step]) 参数 ...
- AWS免费云服务套餐申请步骤及常见问题
AWS免费云服务套餐申请步骤及常见问题 AWS免费使用套餐常见问题_AWS免费云服务套餐_-AWS云服务https://amazonaws-china.com/cn/free/faqs/ 什么是 AW ...