在python中,通过第三方库PIL加载图片尺寸。方法如下:1、使用Image.open函数打开图像;2、利用img的size属性获取图像尺寸。
了解Pillow的人都知道Pillow是一个非常强大的图像处理器,本文主要记录Pillow获取图像信息:
安装Pillow
pipinstallpillow
本地图片
importos fromPILimportImage path=os.path.join(os.getcwd(),"23.png") img=Image.open(path) print(img.format)#PNG print(img.size)#(3500,3500)
远程图片
path="http://h.hiphotos.baidu.com/image/pic/item/c8ea15ce36d33976ba5187e9.jpg" file=urllib2.urlopen(path) tmpIm=cStringIO.StringIO(file.read()) img=Image.open(tmpIm) print(img.format)#JPEG print(img.size)#(801,1200)
推荐课程:python编程入门系列图文教程