- Python Pillow教程
 - 蟒蛇Pillow - 主页
 - Python Pillow - 概述
 - Python Pillow - 环境设置
 - Python Pillow - 使用图像模块
 - Python Pillow - 处理图像
 - Python Pillow - 创建缩略图
 - Python Pillow - 合并图像
 - Python Pillow - 模糊图像
 - Python Pillow - 裁剪图像
 - Python Pillow - 翻转和旋转图像
 - Python Pillow - 调整图像大小
 - Python Pillow - 创建水印
 - Python Pillow - 向图像添加滤镜
 - Python Pillow - 图像上的颜色
 - Python Pillow - ImageDraw 模块
 - Python Pillow - 图像序列
 - Python Pillow - 在图像上写入文本
 - Python Pillow - 使用 Numpy 进行机器学习
 - Python Pillow 有用资源
 - Python Pillow - 快速指南
 - Python Pillow - 有用的资源
 - Python Pillow - 讨论
 
Python Pillow - 裁剪图像
裁剪是图像处理的重要操作之一,用于删除图像中不需要的部分以及向图像添加所需的特征。它在网络应用程序中广泛使用,用于上传图像。
Pillow中图像类的crop()函数要求将部分裁剪为矩形。要从图像中裁剪的矩形部分被指定为四元素元组,并返回已裁剪的图像的矩形部分作为图像对象。
例子
以下示例演示了如何使用 python Pillow 旋转图像 -
#Import required Image library
from PIL import Image
#Create an Image Object from an Image
im = Image.open('images/elephant.jpg')
#Display actual image
im.show()
#left, upper, right, lowe
#Crop
cropped = im.crop((1,2,300,300))
#Display the cropped portion
cropped.show()
#Save the cropped image
cropped.save('images/croppedBeach1.jpg')
输出
如果将上述程序保存为Example.py并执行,它将使用标准PNG显示实用程序显示原始图像和裁剪后的图像,如下所示 -
原图
裁剪图像
