您的位置:首页 > 编程语言 > Python开发

14.Python使用Pillow教程

2020-01-13 23:16 113 查看

1.打算开始学习PIL,在命令行输入:pip3 install PIL,报错信息如下所示,后百度了下,发现:PIL仅支持到Python2.7,后来一群志愿者在此基础上创建了兼容性版本,为Pillow,因此可以直接安装使用Pillow。

2.在命令行输入:pip3 install Pillow,运行一段时间后报错:Read timed out.后输入命令:pip --default-timeout=100 install -U Pillow成功安装

3.使用Image类

 

from PIL import Image

im = Image.open('test.jpg')   #返回Image对象

print(im)
print(im.size)     #二元tuple,包含width和height(单位都是px)
print(im.format)   #属性标识了图像来源
print(im.mode)     #定义图像的数量、名称、像素的类型和深度,L==灰度图像,RGB==真彩色图像,CMYK==出版图像 

 

4.创建缩略图

 

from PIL import Image

im = Image.open('test.jpg')   #返回Image对象

size = (100,100)    #缩小的比例(width和height)
im.thumbnail(size,Image.ANTIALIAS)   #缩略图
im.save('thumbnail.jpg')   #保存

 

  

 

转载于:https://www.cnblogs.com/android-it/p/9561659.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
bannaoshou7980 发布了0 篇原创文章 · 获赞 0 · 访问量 103 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: