Python绘图

1、小甲鱼绘图转码

用的pillow库

from PIL import Image
img = Image.open('mby.jpg')
#L表示灰度模式
out = img.convert('L')
#查看一下图片的大小
print(out.size)
width,height=out.size
#图片太大了,改一下图片的尺寸,将它变得小一点
out = out.resize((int(width*0.1),int(height*0.08)))
width,height=out.size
#从黑到简的一个个字符的模拟
asciis = '@%#*+=-. '
#初始化一个字符串用来保存
texts = ""
for row in range(height-1) :
    for col in range(width-1):
        gray = out.getpixel((col,row))
        texts += asciis[int(gray / 255 * 9)]
        #要记得换行
    texts += '\n'
with open('ll.txt','w') as file :
    file.write(texts)

毛不易

转码后的效果
转码效果

2、验证码

一个加上自定义字体的验证码图片
但要注意你的电脑上是不是有这个字体,在Windows环境,字体一般位于C:\WINDOWS\Fonts文件夹下。用户可以到此文件夹中查看Python程序中指定的字体是否存在。如果不存在,会产生OSError: cannot open resource错误。

from captcha.image import ImageCaptcha

image = ImageCaptcha(fonts=['data/RAVIE.TTF','data/TEMPSITC.TTF'])
image.write('sharon','captcha2.png')
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值