几天前,我在另一个领域问了一个问题,最后我的一个朋友(@emcconville)帮助我编写了一个脚本,用于“在一个文件中恢复每一个JPEG文件”。现在我意识到这个程序只适用于标准"JFIF“的图像,不能用"EXIF”标准(由数码相机拍摄的图像)检索图像。
如何更改程序,使其也可以了解Exif标准的图像?我不熟悉Python,也不知道它的威力。
谢谢
import struct
with open('src.bin', 'rb') as f:
# Calculate file size.
f.seek(0, 2)
total_bytes = f.tell()
# Rewind to beging.
f.seek(0)
file_cursor = f.tell()
image_cursor = 0
while file_cursor < total_bytes:
# Can for start of JPEG.
if f.read(1) == b"\xFF":
if f.read(3) == b"\xD8\xFF\xE0":
print("JPEG FOUND!")
# Backup and find the size of the image
f.seek(-8, 1)
payload_size = struct.unpack('<I', f.read(4))[0]
# Write image to disk
d_filename = 'image{0}.jpeg'.format(image_cursor)
with open(d_filename, 'wb') as d:
d.write(f.read(payload_size))
image_cursor += 1
file_cursor = f.tell()发布于 2018-08-20 13:27:02
EXIF文件的标记为0xffe 1,JFIF文件的标记为0xffe0。因此,所有依赖于0 0xffe0 0来检测JPEG文件的代码都将丢失所有EXIF文件。(从这里开始)
所以只要改变
if f.read(3) == b"\xD8\xFF\xE0":至
if f.read(3) == b"\xD8\xFF\xE1":如果您想检查这两种情况,就不要再那样使用.read()了。相反,就像
x = f.read(3)
if x in (b"\xD8\xFF\xE0", b"\xD8\xFF\xE1"):https://stackoverflow.com/questions/51931715
复制相似问题