【Python】Pillow图片处理库

title: 【Python】Pillow图片处理库
type: categories
date: 2017-03-02 15:26:19
categories: Python

tags: [PIL, Pillow]

Pillow是Python中的图片处理库,来自于PIL,使用时 import PIL;

安装

Python2中安装命令:

 sudo pip install PIL

Python3中安装命令:

sudo pip install Pillow
创建
mg = Image.open('pic.JPG')
print(img.size, img.mode)       # (3264, 2448) RGB
缩略图
size = (200, 200)
img.thumbnail(size)
img.save('/Users/zhangzhao/PycharmProjects/pillow_demo/thum.JPEG')
print(img.size, img.mode)     # (200, 150) RGB
剪切图

剪切函数 crop(box):box = (left, upper, right, lower)

注意:right > left; lower > upper;

剪切后图片长宽: width = right - left; height = lower - upper;

frame = (1632, 0, 3264, 1224) # 图片四分之一右上角部分
crop_img = Image.open('pic.JPG').crop(frame)
crop_img.save('/Users/zhangzhao/PycharmProjects/pillow_demo/crop.jpg')
#crop_img.show()
print(crop_img.size)    # (1632, 1224)
几何转换

尺寸转换

resize_out = crop_img.resize((200, 200))
#resize_out.show()

角度转换

rotate_out = crop_img.rotate(45)    # 逆时针 45
#rotate_out.show()
模式转换
change_mode = resize_out.convert('L')
print(resize_out.mode)  # RGB
print(change_mode.mode) # L

http://www.cnblogs.com/wbin91/p/3971079.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值