【Python】Pillow图片处理库
2017-03-02 15:45
239 查看
title: 【Python】Pillow图片处理库
type: categories
date: 2017-03-02 15:26:19
categories: Python
Python3中安装命令:
注意:right > left; lower > upper;
剪切后图片长宽: width = right - left; height = lower - upper;
角度转换
http://www.cnblogs.com/wbin91/p/3971079.html
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
相关文章推荐
- Python图片处理模块Pillow
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- (python)图片处理Pillow模块的使用
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- Python-PIL(pillow)图片处理入门(一)
- Python图片处理模块PIL(pillow)(2)
- python图片处理模块PIL(pillow)(1)
- Python图片处理PIL/pillow/生成验证码/出现KeyError: 和The _imagingft C module is not installed
- Python 图片处理-图片翻转
- 用python给文件夹下所有图片进行缩放处理
- Python Show-Me-the-Code 第 0005 题 批量图片处理
- 使用python进行图像处理-调整图片大小
- Python图片处理
- 使用python处理没有被Web用到的图片
- [Python] 图像简单处理(PIL or Pillow)
- [Python] 图像简单处理(PIL or Pillow)
- Python练习册--PIL处理图片之加水印
- Python 将pdf转换成txt(不处理图片)
- opencv-python 学习笔记1:简单的图片处理
- python-Image处理图片