bigcat88/pillow_heif

EXIF data are not transferred correctly

fabbaum opened this issue · 3 comments

Describe the bug

With version pillow_heif==0.10.1, the code snip attached below worked perfectly. The EXIF data was read from a HEIC photo and added to a JPG.

With version pillow_heif==0.11.0, the EXIF data is no longer transferred correctly.

Please also compare the two file attachments.

Steps/Code to Reproduce

for files in os.listdir(path_source):
    if files.endswith('.HEIC'):
        filename = files.split('.')[0]
        heif_file = pillow_heif.open_heif(path_source + files, convert_hdr_to_8bit=False, bgr_mode=True)
        np_array = np.asarray(heif_file)
        cv2.imwrite(os.path.join(path_output, filename + '.jpg'), np_array)

        # Add exif to new image
        exif = heif_file.info['exif']
        image_new = Image.open(os.path.join(path_output, filename + '.jpg'))
        image_new.save(path_output + filename + '.jpg', 'JPEG', exif=exif)

Expected Results

The expected result, reproduced with version 0.10.1:
3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
0.10.1
{'libheif': '1.15.2', 'HEIF': 'x265 HEVC encoder (3.4+31-6722fce1f)', 'AVIF': 'AOMedia Project AV1 Encoder v3.6.0'}
Version 0 10 1

Actual Results

Version 0 11 0

Versions

3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
0.11.0
{'libheif': '1.15.2', 'HEIF': 'x265 HEVC encoder (3.4+31-6722fce1f)', 'AVIF': 'AOMedia Project AV1 Encoder v3.6.0'}

It is not a bug, just correct returning of Exif from libheif.
Exif can possible be without bExif\x00\x00 sequence at the beginning(those Pillow just do not support this with explictly exif parameter).
But 0.11.0 version really breaks compatibility with previous versions in way you described...

The only way currenly see to restore compatability for me looks like always append bExif\x00\x00 at the start of Exif if it is not present...

I'll add test for this case you described and publish an update that restores compatibility and do not return the bug that was fixed previously in 0.11.0

Thanks for pointing on this!

image_new.save(path_output + filename + '.jpg', 'JPEG', exif=b'Exif\x00\x00' + exif)

If with this release all is good, and in three days there will be no issues I'll mark 0.11.0 version as yanked.

Feel free to close issue after check that the problem is gone for you

The release ist good. Thank you very much for the quick implementation.