Add a serialization option for EXIF dictionaries #129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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!🐍 🤹♂️