PIL是Python Imaging Library,它為python解釋器提供了圖像編輯函數。的Image
模塊提供了一個具有相同名稱的類,用於表示PIL圖像。該模塊還提供了許多出廠函數,包括從文件加載圖像和創建新圖像的函數。
Image.thumbnail()
將此圖像製作為縮略圖。此方法將圖像修改為包含其自身的縮略圖版本,但不大於給定的大小。此方法計算適當的縮略圖大小以保留圖像的外觀,draft()
配置文件閱讀器(如果適用)並最終調整圖像大小的方法。
請注意,此函數會在適當位置修改Image對象。如果您還需要使用全分辨率圖像,請將此方法應用於copy()
原始圖像。
用法: Image.thumbnail(size, resample=3)
參數:
size-要求的尺寸。
resample-可選的重采樣過濾器。
返回類型:Image對象。
使用的圖片:
# importing Image class from PIL package
from PIL import Image
# creating a object
image = Image.open(r"C:\Users\System-Pc\Desktop\python.png")
MAX_SIZE = (100, 100)
image.thumbnail(MAX_SIZE)
# creating thumbnail
image.save('pythonthumb.png')
image.show()
輸出:
另一個示例:這裏使用了另一個圖像。
使用的圖片:
# importing Image class from PIL package
from PIL import Image
# creating a object
image = Image.open(r"C:\Users\System-Pc\Desktop\house.jpg")
MAX_SIZE = (500, 500)
image.thumbnail(MAX_SIZE)
# creating thumbnail
image.save('pythonthumb2.jpg')
image.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.thumbnail() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。