python
主页 > 脚本 > python >

基于Python获取图片的物理尺寸方法

2019-11-25 | 秩名 | 点击:

问题

如何获取图片的物理尺寸,而非(width, height)?

代码

以女神图为例
 


 

#! -*- coding: utf-8 -*-
import requests
import io
url = "http://s1.sinaimg.cn/large/001Db1PVzy7qxVQWMjs06"
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))
 

结果

75264 byte
75.264 kb
0.075264 Mb

注意

实际大小要除以1000,而非1024
原文链接:http://www.freesion.com/article/70774932/
相关文章
最新更新