1. 程式人生 > >PIL 影象旋轉並儲存

PIL 影象旋轉並儲存

from PIL import Image

# 讀取圖片
img = Image.open(r'./000001.jpg')

# 轉化為alpha層
img_alpha = img.convert('RGBA')

# 旋轉影象
rot = img_alpha.rotate(45, expand = 1)

# 與旋轉影象大小相同的白色區域
fff = Image.new('RGBA', rot.size, (255,255,255,255))

# # 使用rot作為建立一個複合影象
out = Image.composite(rot, fff, mask=rot)


out.convert(img.mode).show()
# out.convert(img.mode).save("./1.jpg")