如何在python中获取调用图片的大小?
发布时间:2026-03-19 22:13:05

Pillow库中的imgg需要在Pillow库中获取图片大小.size方法。
安装Pillow
pipinstallpillow
获取本地图片的大小:
importos fromPILimportImage path=os.path.join(os.getcwd(),"23.png") img=Image.open(path) printimg.format#PNG printimg.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) printimg.format#JPEG printimg.size#(801,1200)
请关注Python自学网了解更多Python知识。
