使用 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