Python Pillow 教學

Author: Kelvin Huang

您可以使用 Python 搭配 Pillow 製作影像處理效果, Pillow 主要功能清單 :

功能 效果 備註
載入 / 儲存 支援影像格式(JPG / PNG / GIF / BMP / TIFF / WebP 等) Pillow 支援多種影像格式
圖像基本屬性 取得尺寸 (Size)、格式 (Format)、模式 (Mode) img.size, img.format, img.mode
色彩空間轉換 模式轉換(例如 RGB 轉灰階 / RGBA / CMYK) im.convert("L") 等
影像調整 Resize (縮放) / Rotate (旋轉) / Transpose (翻轉、旋轉) / Crop (裁切) / Paste (貼上) im.resize(), im.rotate(), im.transpose(), im.crop(), im.paste()
影像混合 Blend (線性混合) / Composite (依遮罩結合) / Alpha_composite (alpha 混合) Image.blend(), Image.composite(), Image.alpha_composite()
影像增強 對比度 (Contrast) / 亮度 (Brightness) / 顏色 (Color) / 銳利度 (Sharpness) 使用 ImageEnhance 模組,例如 ImageEnhance.Contrast(im).enhance(factor)
濾鏡效果 模糊 (Blur) / 銳化 (Sharpen) / 細節 (Detail) / 輪廓 (Edge_Enhance) / Emboss / Smooth / 等 使用 ImageFilter 模組與 im.filter(...)
序列動畫 支援多影格圖像 (如 GIF) 、開啟多幀 (seek / tell)、儲存動畫 (save_all 等參數) ImageSequence, save(..., save_all=True, append_images=…)
新建畫布 Image.new() 創建指定模式與大小的空白影像 Image.new(mode, size, color)

Pillow 主頁 [ https://pillow.readthedocs.io/ ]

Pillow Tutorial [ https://pillow.readthedocs.io/en/stable/handbook/tutorial.html ]

Pillow Image 模組參考 (API) [ https://pillow.readthedocs.io/en/stable/reference/Image.html ]

 

 

 

 

Copyright © 2025 CG Digital Corp. All rights reserved.