Pillow教程(二)
来源:互联网 发布:好听的网络歌手歌曲 编辑:程序博客网 时间:2024/06/11 18:33
图片加上文字
from PIL import Image,ImageDraw,ImageFontim = Image.open('tu.jpg')draw = ImageDraw.Draw(im)(width, height) = im.sizemyfont = ImageFont.truetype('yuanqi.ttf',size = 120)fillcolor = 'pink'#第一个参数是加入字体的坐标#第二个参数是文字内容#第三个参数是字体格式#第四个参数是字体颜色draw.text( (60,100) , u'萌萌哒' ,font = myfont , fill = fillcolor )im.save('tu_word.jpg')
图片加上数字
from PIL import Image,ImageDraw,ImageFontim = Image.open('tu.jpg')draw = ImageDraw.Draw(im)(width, height) = im.sizemyfont = ImageFont.truetype('yuanqi.ttf',size = 120)#在图上画一个圆,ellipse参数分别为 左上角的坐标,右下角的坐标#ellipse(左上X , 左上Y , 右下X , 右下Y)draw.ellipse((width-200, 0 ,width,200),fill="red",outline="red") draw.text((width-120,20 ),'5',font=myfont,fill='white')im.save('tu_number.jpg')
将图片转化成字符画
#coding:utf-8from PIL import Image#要索引的字符列表ascii_char = list("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. ")length = len(ascii_char) #读取图像文件def readImg(): img = Image.open('kai.png') (width,height) = img.size img = img.resize( ( int(width * 0.9) , int(height * 0.5) )) print(img.size) return imgdef convert(img): # 转为灰度图像 img = img.convert('L') txt = '' for y in range(img.size[1]): for x in range(img.size[0]): # 获取每个坐标像素点的灰度 gray = img.getpixel((x,y)) unit = 256.0 / length txt += ascii_char[(int)(gray/unit)] txt += '\n' return txtif __name__ == '__main__': txt = convert(readImg()) with open('kai.txt','w') as f: f.write(txt)
原图:
字符:
阅读全文
0 0
- Pillow教程(二)
- Pillow教程(一)
- [python + pillow] 自制壁纸不完全教程
- Pillow for 2.7.0 教程(1)
- Pillow学习之Image类(二)
- Python-pillow
- 安装pillow
- pillow安装
- python pillow
- LV Pillow Series
- python PIL PILLOW
- Mac下安装Pillow
- mac 安装pillow模块
- Pillow依赖库安装
- 使用python的pillow
- python pillow模块
- Ubuntu下安装Pillow
- python安装Pillow
- log4r包
- nyoj 2354 分班级(经典二分)
- Ext4.1.1使用rowexpander
- sublime设置
- [JAVA] Hibernate Component组件映射
- Pillow教程(二)
- python3的练习----求素数
- 多态
- 新手常用的sublime tex3插件安装及其应用
- 软键盘的删除事件的监听
- 如何判断当前进程是在32位/64位系统上运行
- 数据库的存储过程
- keytool生成keystore、truststore、证书以及SSL单向认证在服务端tomcat和客户端的配置
- 借助Nginx搭建反向代理服务器