exif-py icon indicating copy to clipboard operation
exif-py copied to clipboard

Add a serialization option for EXIF dictionaries

Open EtiennePelletier opened this issue 5 years ago • 4 comments

Many have requested this feature for a while (#59, #110). With Python 2 being dropped in the next release, the task to add a serialization option becomes more simple.

Converting IfdTags to native Python types cannot be done exclusively after parsing the EXIF tags currently because there is no way to know if the IfdTag.values were converted to a meaningful printable value (could be an enum, a make_string, etc) during processing (this depends on the tag definitions). This pull request adds a prefer_printable attribute to the IfdTag class that allows an external function to do the conversions properly.

In order to use the suggested conversion function, builtin_types=True kwarg can be added to calls to process_file:

exifread.process_file(..., builtin_types=True, ...)

A few fields contain or may contain binary data, preventing immediate dump to JSON (if chosen as serialization format, although databases like MongoDB handle storing binary natively). The tags are mainly JPEGThumbnail, TIFFThumbnail, EXIF MakerNote and MakerNote Tag 0x####, but there are more. If JSON is strictly preferred, binary values can be handled afterwards in any appropriate way depending on the use case, or mainly excluded from the output dictionary with exifread.process_file(..., details=False, ...).

I updated the utils.get_gps_coords function to support both Exif tags where values are either IfdTag or native types. This also addresses https://github.com/ianare/exif-py/issues/193.

All changes in this pull request are fully backwards compatible with current develop branch. I am open to any feedback!

:snake: :man_juggling:

EtiennePelletier avatar Nov 05 '20 02:11 EtiennePelletier

This is great, thank you. I would like to take some time for testing and analysis but globally it looks good to me.

ianare avatar Nov 06 '20 10:11 ianare

Hi @ianare , have you been able to have a look? A new release with this would be awesome! Thanks!

EtiennePelletier avatar Aug 30 '21 22:08 EtiennePelletier

PR has been updated to fix conflicts from develop branch changes and account for import structure changes.

EtiennePelletier avatar Nov 20 '22 19:11 EtiennePelletier