From 6e8aaf3338b9c272549d5d2f522d62f97745530e Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Wed, 4 Mar 2020 15:17:56 +0100 Subject: [PATCH] Started, to re-write using pyexiv2. Can already read DateTimeOriginal :-) --- Readme.md | 3 +++ exif_rad.py | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Readme.md b/Readme.md index 8c24b0a..257695b 100644 --- a/Readme.md +++ b/Readme.md @@ -12,6 +12,9 @@ It then creates a `UserComment` Exif tag with the actual measured radiation at t Right now it depends on the following non-core Python 3 libraries: * [piexif](https://pypi.org/project/pyexif/): Python module for working with EXIF image data. + * [py3exiv2](https://pypi.org/project/py3exiv2/) A Python 3 binding to the library exiv2. + * [boost.python3](http://www.boost.org/libs/python/doc/index.html) Welcome to Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language. + * [exiv2](http://www.exiv2.org/) Exiv2 is a Cross-platform C++ library and a command line utility to manage image metadata. ## Requirements * GeigerCounter log file in csv format as it is being exported by the software GeigerLog. diff --git a/exif_rad.py b/exif_rad.py index 57f5efb..246c764 100755 --- a/exif_rad.py +++ b/exif_rad.py @@ -3,15 +3,13 @@ """Iterates over a bunch of .jpg or .cr2 files and matches DateTimeOriginal from Exif tag to DateTime in a csv log -of a GeigerMuellerCounter.""" +of a GeigerMuellerCounter. """ from datetime import datetime import os import csv import argparse -from PIL import Image -import piexif -import piexif.helper +import pyexiv2 # SIFACTOR for GQ Geiger counters @@ -39,9 +37,11 @@ parser.add_argument('-o', '--outdir', type=str, default='.', args = parser.parse_args() for photo in args.photos: - # Load Image and EXIF data - im = Image.open(photo) - exif_dict = piexif.load(im.info['exif']) + # Load Exif data from image + metadata = pyexiv2.ImageMetadata(photo) + metadata.read() + tag = metadata['Exif.Photo.DateTimeOriginal'] + picrawtime = tag.raw_value # Get image file name out of path photo_basename = os.path.basename(photo) @@ -50,7 +50,6 @@ for photo in args.photos: csvreader = csv.reader(filter(lambda row: row[0] != '#', f), delimiter=',', skipinitialspace=True) - picrawtime = exif_dict['Exif'][piexif.ExifIFD.DateTimeOriginal].decode('ASCII') picisotime = datetime.strptime(picrawtime, "%Y:%m:%d %H:%M:%S") print('Processing file:', photo_basename, end='\r') for _, csvrawtime, csvrawcpm, _ in csvreader: @@ -61,15 +60,15 @@ for photo in args.photos: # convert str to exif compatible string new_comment = 'Radiation ☢ ' + str(rad) + ' µS/h' - user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode") - exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment +# user_comment = piexif.helper.UserComment.dump(new_comment, encoding="unicode") +# exif_dict["Exif"][piexif.ExifIFD.UserComment] = user_comment # compile and write tags - exif_bytes = piexif.dump(exif_dict) +# exif_bytes = piexif.dump(exif_dict) # be os aware and use the correct directory delimiter outfile = os.path.join(args.outdir, photo_basename) - im.save(outfile, exif=exif_bytes) + # write target file # print output print('{:<30} {:<20} {:<22}'.format(photo_basename, str(picisotime), new_comment)) break