Naposledy aktivní 9 months ago

PIL(Pillow)是一個強大的 Python 影像處理庫,可用於開啟、編輯、轉換與儲存影像,適用於影像分析、自動化處理與視覺化應用。

pillow_example.py Raw
1from PIL import Image
2
3# 開啟影像
4image = Image.open("example.jpg")
5
6# 顯示影像
7image.show()
8
9# 轉換為灰階
10gray_image = image.convert("L")
11gray_image.save("example_gray.jpg")
12
13# 調整大小
14resized_image = image.resize((200, 200))
15resized_image.save("example_resized.jpg")
16
17# 旋轉影像
18rotated_image = image.rotate(45)
19rotated_image.save("example_rotated.jpg")
20
21print("影像處理完成!")
22