如何在python里获取导入图片的大小?
发布时间:2026-03-02 21:58:22

将图片大小导入python的方法:
1、获取图片尺寸
importos fromPILimportImage path=os.path.join(os.getcwd(),"23.png") img=Image.open(path) printimg.format#PNG printimg.size#(3500,3500)
2、获取图片的物理大小
#!-*-coding:utf-8-*-
importrequests
importio
url="http://s1.sinaimg.cn/large/001DB1PVzy7qqwwws06"
image=requests.get(url).content
image_b=io.BytesIO(image).read()
size=len(image_b)
print("{}byte\n{}kb\n{}Mb".format(size,size/1e3,size/1e6))请关注Python自学网了解更多Python知识。
下一篇 python语言用来干什么的?
