了解过Pillow的都知道,Pillow是一个非常强大的图片处理器,这篇文章主要记录一下Pillow对图片信息的获取:
安装Pillow
pip install pillow
本地图片
import os
from PIL import Image
path = os.path.join(os.getcwd(),"23.png")
img = Image.open(path)
print img.format # PNG
print img.size # (3500, 3500)
远程图片
path = "/file/imgs/upload/202301/31/pjhsujstq0c.jpg"
file = urllib2.urlopen(path)
tmpIm = cStringIO.StringIO(file.read())
img = Image.open(tmpIm)
print img.format # JPEG
print img.size # (801, 1200)