标签: jfif

如何通过 EXIF / JFIF 签名检测 JPEG 文件?

几天前,我在另一个领域提出了一个问题,最后一位朋友(@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') …
Run Code Online (Sandbox Code Playgroud)

python exif jfif

1
推荐指数
1
解决办法
1538
查看次数

标签 统计

exif ×1

jfif ×1

python ×1