ianare / exif-py

Easy to use Python module to extract Exif metadata from digital image files.
BSD 3-Clause "New" or "Revised" License
832 stars 191 forks source link

Add a serialization option for EXIF dictionaries #129

Open EtiennePelletier opened 3 years ago

EtiennePelletier commented 3 years ago

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 slightly 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, convert_ifdtag=True kwarg can be added to calls to process_file:

exifread.process_file(..., convert_ifdtags=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.

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

:snake: :man_juggling:

ianare commented 3 years ago

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

EtiennePelletier commented 3 years ago

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

EtiennePelletier commented 1 year ago

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