我正在尝试编写一个 python 函数来解析 jpeg 文件的宽度和高度。我目前的代码看起来像这样
import struct
image = open('images/image.jpg','rb')
image.seek(199)
#reverse hex to deal with endianness...
hex = image.read(2)[::-1]+image.read(2)[::-1]
print(struct.unpack('HH',hex))
image.close()
Run Code Online (Sandbox Code Playgroud)
不过,这有几个问题,首先我需要浏览文件以找出从哪里读取(在 ff c0 00 11 08 之后),其次我需要避免从嵌入的缩略图中获取数据。有什么建议么?