PIL是Python Imaging Library,它為python解釋器提供了圖像編輯函數。的Image
模塊提供了一個具有相同名稱的類,用於表示PIL圖像。該模塊還提供了許多出廠函數,包括從文件加載圖像和創建新圖像的函數。
Image.transpose()
轉置圖像(以90度為單位翻轉或旋轉)
用法: Transpose image (flip or rotate in 90 degree steps)
參數:
method-PIL.Image.FLIP_LEFT_RIGHT,PIL.Image.FLIP_TOP_BOTTOM,PIL.Image.ROTATE_90,PIL.Image.ROTATE_180,PIL.Image.ROTATE_270或PIL.Image.TRANSPOSE之一。
返回類型:圖像對象。
使用的圖片:
# Improting Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\new.jpg")
# Size of the image in pixels (size of orginal image)
# (This is not mandatory)
width, height = im.size
# Setting the points for cropped image
left = 6
top = height / 4
right = 174
bottom = 3 * height / 4
# Cropped image of above dimension
# (It will not change orginal image)
im1 = im.crop((left, top, right, bottom))
newsize = (200, 200)
im1 = im1.transpose(Image.FLIP_LEFT_RIGHT)
# Shows the image in image viewer
im1.show()
輸出:
另一個例子:此處,變換參數已更改。
圖片已使用
# Improting Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"C:\Users\System-Pc\Desktop\flower1.jpg")
# Size of the image in pixels (size of orginal image)
# (This is not mandatory)
width, height = im.size
# Setting the points for cropped image
left = 3
top = height / 2
right = 164
bottom = 3 * height / 2
# Cropped image of above dimension
# (It will not change orginal image)
im1 = im.crop((left, top, right, bottom))
newsize = (1800, 1800)
im1 = im1.transpose(Image.FLIP_TOP_BOTTOM)
# Shows the image in image viewer
im1.show()
輸出:
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python Decimal max()用法及代碼示例
- Python PIL ImageOps.fit()用法及代碼示例
- Python os.rmdir()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python Decimal min()用法及代碼示例
- Python os.readlink()用法及代碼示例
- Python os.writev()用法及代碼示例
- Python os.readv()用法及代碼示例
- Python PIL RankFilter()用法及代碼示例
- Python os.rename()用法及代碼示例
- Python os.sendfile()用法及代碼示例
注:本文由純淨天空篩選整理自Sunitamamgai大神的英文原創作品 Python PIL | Image.transpose() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。