# Big ugly patch to deal with APP2 (or other) data coming before APP1 fh.seek(0) # in theory, this could be insufficient since 64K is the maximum size--gd data = fh.read(base + 4000)
base = _get_base(base, data)
fh.seek(base + 12) if ord_(data[2 + base]) == 0xFFand data[6 + base : 10 + base] == b"Exif": # detected EXIF header offset = fh.tell() endian = fh.read(1) # HACK TEST: endian = 'M' elif ord_(data[2 + base]) == 0xFFand data[6 + base : 10 + base + 1] == b"Ducky": # detected Ducky header. logger.debug( "EXIF-like header (normally 0xFF and code): 0x%X and %s", ord_(data[2 + base]), data[6 + base : 10 + base + 1], ) offset = fh.tell() endian = fh.read(1) elif ord_(data[2 + base]) == 0xFFand data[6 + base : 10 + base + 1] == b"Adobe": # detected APP14 (Adobe) logger.debug( "EXIF-like header (normally 0xFF and code): 0x%X and %s", ord_(data[2 + base]), data[6 + base : 10 + base + 1], ) offset = fh.tell() endian = fh.read(1) else: # no EXIF information msg = "No EXIF header expected data[2+base]==0xFF and data[6+base:10+base]===Exif (or Duck)" msg += "Did get 0x%X and %s" % (ord_(data[2 + base]), data[6 + base : 10 + base + 1]) raise InvalidExif(msg) return offset, endian, fake_exif
data = fh.read(base + 4000) 不够获取修改过后的exif 信息, 无法成功解析图像中的 exif 数据。