如何獲取圖片的物理尺寸,而非(width, height)?
#! -*- coding: utf-8 -*- import requests import io url = "https://i.loli.net/2019/11/23/Q7NAVgfWp8YnhSl.jpg" image = requests.get(url).content #image = open('lyf.jpg', 'rb').read() image_b = io.BytesIO(image).read() size = len(image_b) print("{} byte\n{} kb\n{} Mb".format(size, size / 1e3, size / 1e6))
結果:
52921 byte
52.921 kb
0.052921 Mb
與計算機顯示的真實結果是一樣的: