【发布时间】:2011-08-16 15:13:24
【问题描述】:
我正在尝试编写一个 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()
这有几个问题,首先我需要查看文件以确定从哪里读取(在 ff c0 00 11 08 之后),其次我需要避免从嵌入的缩略图中获取数据。有什么建议吗?
【问题讨论】:
标签: python binary python-3.x hex jpeg