-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a serialization option for EXIF dictionaries #129
base: develop
Are you sure you want to change the base?
Conversation
039f7ad
to
38a4869
Compare
This is great, thank you. I would like to take some time for testing and analysis but globally it looks good to me. |
Hi @ianare , have you been able to have a look? A new release with this would be awesome! Thanks! |
PR has been updated to fix conflicts from develop branch changes and account for import structure changes. |
05fe609
to
04efa3f
Compare
- Improve documentation - Modular code is much easier to test and better type annotated - None is returned instead of empty string for empty tags
ce3c640
to
ce35665
Compare
Hi @ianare, I’ve updated this branch to include the latest changes and resolve conflicts. I also took the opportunity to:
In addition, I've made changes to ensure the tests pass (see PR #202). I've tested the new functionality extensively on the sample images as well as additional ones. Since serialization is optional, I haven’t added automated tests for this feature yet, but I’m open to doing so once related PRs are merged. Other improvements since opening this PR in 2020 include:
To help with future debugging and testing, here are some commands I used to refine the conversion functions. You’ll need to uncomment the debugging code to use them. # Run EXIF.py with builtin type option and output to 'serialize_test'
$ find ../exif-samples -regextype posix-egrep -iregex ".*\.(bmp|gif|heic|heif|jpg|jpeg|png|tiff|webp)" -print0 | LC_COLLATE=C sort -fz | xargs -0 EXIF.py -b > serialize_test
# Shows how many exif values from each field_type were converted, grouped by the output built-in type and conversion function used
$ grep convert_ serialize_test | sort | uniq -c
# Display specific input-to-output conversions, sorted by frequency (modify first grep argument for use case)
$ grep "convert_ascii: 2 to str" -A 1 serialize_test | grep -vP "(convert_|^--)" | sort | uniq -c | sort -h Sample output listing type conversion paths
Sample output (truncated to last few lines only) showing Exif values that had field type 2 (ascii) and were converted to a string
Thank you for considering this contribution. |
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: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 #193.All changes in this pull request are fully backwards compatible with current
develop
branch. I am open to any feedback!🐍 🤹♂️