這篇文章主要介紹了python Pillow圖像處理方法匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
Pillow中文文檔:https://pillow-cn.readthedocs.io/zh_CN/latest/handbook/tutorial.html
安裝:pip install pillow
操作圖像:
#!/usr/bin/env python3 # _*_ coding utf-8 _*_ __author__ = 'nxz' from PIL import Image, ImageFilter from time import sleep # 打開(kāi)一個(gè)jpg圖像文件 im = Image.open('test.jpg') w, h = im.size # print('圖片的寬:%s,和高:%s' % (w, h)) # 圖片縮放 im.thumbnail((w // 2, h // 2)) w, h = im.size print(w, h) # 縮放之后的圖片重新保存 im.save('thumbnail.jpg', 'jpeg') # 其他功能:切片、旋轉(zhuǎn)、濾鏡、輸出文字、調(diào)色板 # 模糊效果 im2 = im.filter(ImageFilter.BLUR) im2.save('blur.jpg','jpeg')