码迷,mamicode.com
首页 > 其他好文 > 详细

获取图片大小

时间:2019-12-24 18:30:36      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:b2b   线图   image   string   http   idt   width   img   tmp   

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

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]  高度

获取图片大小

标签:b2b   线图   image   string   http   idt   width   img   tmp   

原文地址:https://www.cnblogs.com/one-tom/p/12092672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!