使用 Pillow 库裁剪图像
在本教程中,我们将使用 Pillow 库裁剪图像。为此,我们将使用 crop() 函数。该函数采用左、上、右、下像素坐标来裁剪图像。
原图像

算法
Step 1: Import Image from Pillow. Step 2: Read the image. Step 3: Crop the image using the crop function. Step 4: Display the output.
示例代码
from PIL import Image
im = Image.open('testimage.jpg')
width, height = im.size
left = 5
top = height / 2
right = 164
bottom = 3 * height / 2
im1 = im.crop((left, top, right, bottom))
im1.show()输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
JavaScript
PHP