小编给大家分享一下在python中获取调用图片大小的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

python中获取图片大小需要使用Pillow库中的img.size方法。

安装Pillow

pipinstallpillow

获取本地图片的大小:

importosfromPILimportImagepath=os.path.join(os.getcwd(),"23.png")img=Image.open(path)printimg.format#PNGprintimg.size#(3500,3500)

获取远程图片的大小:

path="http://h.hiphotos.baidu.com/image/pic/item/c8ea15ce36d3d5397966ba5b3187e950342ab0cb.jpg"file=urllib2.urlopen(path)tmpIm=cStringIO.StringIO(file.read())img=Image.open(tmpIm)printimg.format#JPEGprintimg.size#(801,1200)

看完了这篇文章,相信你对在python中获取调用图片大小的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!