共計 453 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 Python 中,可以使用 PIL 庫(Python Imaging Library)的 Image 函數來處理圖像。具體使用方法如下:
首先,需要安裝 PIL 庫。在命令行中輸入以下命令進行安裝:
pip install Pillow
然后,在 Python 腳本中導入 PIL 庫:
from PIL import Image
接下來,可以使用 Image 函數來打開、創建、保存和顯示圖像。下面是一些常用的 Image 函數用法:
- 打開圖像文件:
image = Image.open("image.jpg") # 打開圖像文件
- 創建新的圖像:
new_image = Image.new("RGB", (width, height), "white") # 創建一個新的白色圖像
- 保存圖像文件:
image.save("new_image.jpg") # 保存圖像文件
- 顯示圖像:
image.show() # 顯示圖像
此外,Image 函數還提供了很多其他方法,如調整圖像大小、裁剪圖像、旋轉圖像、添加文字、應用濾鏡等。可以根據具體需求使用不同的方法來處理圖像。
丸趣 TV 網 – 提供最優質的資源集合!
正文完