获取图片大小

Posted one-tom

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取图片大小相关的知识,希望对你有一定的参考价值。

第一种方法:获取在线图片的宽 高信息

from io import StringIO,BytesIO
from pil import Image
from urllib import request
url = http://e.hiphotos.baidu.com/image/h%3D300/sign=a9e671b9a551f3dedcb2bf64a4eff0ec/4610b912c8fcc3cef70d70409845d688d53f20f7.jpg
file = request.urlopen(url)
tmpIm = BytesIO(file.read())
im = Image.open(tmpIm)
print(im.format, im.size, im.mode)
# JPEG (450, 300) RGB

第二种:

from pil import Image
img = Image.open("name.jpg")
image_width=img.size[0]
image_heigh=img.size[1]
print(image_heigh,image_width)
# img.size[0]  宽度
# img.size[1]  高度

以上是关于获取图片大小的主要内容,如果未能解决你的问题,请参考以下文章