ในโปรแกรมนี้ เราจะครอบตัดรูปภาพโดยใช้ไลบรารี่ Pillow เราจะใช้ฟังก์ชันการครอบตัด () สำหรับสิ่งเดียวกัน ฟังก์ชันจะใช้พิกัดพิกเซลซ้าย บน ขวา ล่างเพื่อครอบตัดรูปภาพ
ภาพต้นฉบับ

อัลกอริทึม
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() ผลลัพธ์
