如何在python中获取调用图片的大小?

图片[1]-如何在python中获取调用图片的大小?-uusu优素-乐高,模型,3d打印,编程

python中获取图片大小需要使用Pillow库中的img.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://uusucn.zbbe.cn/wp-content/uploads/2024/01/c8ea15ce36d3d5397966ba5b3187e950342ab0cb.jpg"
file=urllib2.urlopen(path)
tmpIm=cStringIO.StringIO(file.read())
img=Image.open(tmpIm)
printimg.format#JPEG
printimg.size#(801,1200)
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容