# -*-coding:utf-8-*-

'''
题目描述:
使用 Python 生成类似于下图中的字母验证码图片 思路:
运用PIL库加random 随机字母进行生成 ''' import random
import string
from PIL import Image, ImageDraw, ImageFont, ImageFilter def rnword():
return random.choice(string.letters) def color():
return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255)) def color2():
return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127)) def draw(width, height, n):
bgcolor = (255, 2155, 255)
image = Image.new('RGB', (width, height), bgcolor)
font = ImageFont.truetype('C:/windows/fonts/Arial.ttf', 30)
fontcolor = (0, 0, 0)
draw = ImageDraw.Draw(image) for x in range(width):
for y in range(height):
draw.point((x, y), fill=color()) for w in range(n):
draw.text((60 * w + 10, 10), rnword(), font=font, fill=color2()) image = image.filter(ImageFilter.BLUR)
image.save('test3.jpg', 'jpeg') if __name__ == '__main__':
draw(240, 60, 4)

python练习册 每天一个小程序 第0010题的更多相关文章

  1. python练习册 每天一个小程序 第0013题

    # -*-coding:utf-8-*- ''' 题目描述: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) 地址: http://tieba.baidu.com/p/21 ...

  2. python练习册 每天一个小程序 第0001题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生 ...

  3. python练习册 每天一个小程序 第0007题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但 ...

  4. python练习册 每天一个小程序 第0000题

    PIL库学习链接:http://blog.csdn.net/column/details/pythonpil.html?&page=1 1 #-*-coding:utf-8-*- 2 __au ...

  5. python练习册 每天一个小程序 第0009题

    1 ''' 2 题目描述: 3 找出一个html文件中所有的url 4 5 思路 : 6 利用正则表达式进行匹配 7 8 ''' 9 10 11 import re 12 13 14 with ope ...

  6. python练习册 每天一个小程序 第0008题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 一个HTML文件,找出里面的正文. 6 7 思路: 8 利用Beautiful ...

  7. python练习册 每天一个小程序 第0006题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都 ...

  8. python练习册 每天一个小程序 第0005题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目说明: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小 ...

  9. python练习册 每天一个小程序 第0012题

    # -*-coding:utf-8-*- def test(content): text = content flag = 0 with open('filtered_words.txt') as f ...

随机推荐

  1. Solution -「CF 923E」Perpetual Subtraction

    \(\mathcal{Description}\)   Link.   有一个整数 \(x\in[0,n]\),初始时以 \(p_i\) 的概率取值 \(i\).进行 \(m\) 轮变换,每次均匀随机 ...

  2. Intellij IDEA出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver处理办法

    菜单-->File-->project structure-->Modules-->Dependencies-->添加MySQL的驱动包:mysql-connector- ...

  3. Java 使用jcifs读写共享文件夹报错jcifs.smb.SmbException: Failed to connect: 0.0.0.0<00>/10.1.*.*

    Q:使用jcifs读写Windows 10 共享文件夹中的文件报jcifs.smb.SmbException: Failed to connect: 0.0.0.0<00>/10.1.*. ...

  4. JSP中引入JQuery和Layer,浏览器控制台报错404

    路径没有写错,文件也存在为什么会报404呢?,解决方法是将layer文件夹使用source的方式 解决办法: 这时候你会发现layer文件夹变成了蓝色,重启一次服务器,页面中就没有报404异常了 总结 ...

  5. 【笔试必备】常见sql笔试题(30题)

    sql是测试从业者必备的技能之一,基本上也是笔试必考内容. 所以,不要让sql拖了后腿,有些测友一遇到多表关联查询就犯晕,甚至连单表的执行顺序都没搞懂,下面简单介绍下,顺便给一些题供大家练习. 单表执 ...

  6. oracle11g在windows下安装

    oracle下载 https://www.oracle.com/database/technologies/oracle-database-software-downloads.html 下载11g ...

  7. Centos7 增加swap分区的内存大小

    Centos7 增加swap分区的内存大小 对 swap 空间的适当大小实际上取决于您的个人偏好和您的应用程序要求.通常,等于或双倍于系统内存的量是一个很好的选择 添加swap分区使用dd命令创建/h ...

  8. 主流的商业智能BI工具推荐,学会数据分析没难度

    伴随着大数据概念的深入企业越来越重视大数据,商业智能BI工具已经成为许多企业数据分析的首选.也许有些小伙伴对商业智能BI工具还是有些陌生,在了解商业智能BI工具之前,先来了解一下什么是商业智能. 百度 ...

  9. Ajax 实战(一)

    目录 Ajax 实战(一) 简介 入门案例 基于Ajax进行登录验证 HTTP请求编码格式和报文 Content-Type=application/x-www-form-urlencoded Cont ...

  10. 矩池云上如何修改cudnn版本

    修改与之前修改nvcc.cuda这些的原理是一样的. 国内镜像 https://mirrors.cloud.tencent.com/nvidia-machine-learning/ 检查系统版本 so ...