在不获取全部内容的情况下查找图像的大小或类型。
imgsp的Python项目详细描述
imgspy通过获取给定url的图像的元数据(类型、大小) 尽可能少。这是fastimage的python实现。支架 图像类型bmp,cur,gif,ico,jpeg,png,psd,tiff,webp。
用法
>>> imgspy.info('http://via.placeholder.com/1920x1080') {'type': 'png', 'width': 1920, 'height': 1080} >>> with requests.get('http://via.placeholder.com/1920x1080', stream=True) as res: ... imgspy.info(res.raw) {'type': 'png', 'width': 1920, 'height': 1080} >>> imgspy.info('/path/to/image.jpg') {'type': 'jpg', 'width': 420, 'height': 240} >>> with open('/path/to/image.jpg') as f: ... imgspy.info(f) {'type': 'jpg', 'width': 420, 'height': 240}