Write exif data if missing

This commit is contained in:
Antonio J. Delgado 2021-09-06 17:10:01 +03:00
parent 6deb7c28b9
commit ebb2237d45

View file

@ -72,27 +72,29 @@ class image_classifier:
with open(file, 'rb') as image_file:
self.exif_info = exif.Image(image_file)
if self.exif_info.has_exif:
for key in self.exif_info.list_all():
for key in dir(self.exif_info):
if key != 'cannot read a base/unknown IFD tag instance':
sys.stdout.write(f"{key}: ")
sys.stdout.write(self.exif_info[key])
self.append_people_to_exif(people)
with open(file, 'wb') as new_image_file:
new_image_file.write(self.exif_info.get_file())
else:
self._log.debug("No exif info in the image.")
self.append_people_to_exif(people)
with open(file, 'wb') as new_image_file:
new_image_file.write(self.exif_info.get_file())
# get date
# move to destination
else:
self._log.debug("Doesn't seem to be an image.")
def append_people_to_exif(self, people):
if self.is_json(self.exif_info['user_comment']):
if self.is_json(self.exif_info.get('user_comment')):
data = json.loads(self.exif_info['user_comment'])
if 'PeopleDetected' not in data:
data['PeopleDetected'] = list()
else:
data = {"previous_user_comment": self.exif_info['user_comment']}
data = dict()
if self.exif_info.get('user_comment'):
data["previous_user_comment"]=self.exif_info.get('user_comment')
data['PeopleDetected'] = list()
for person in people:
data['PeopleDetected'].append(person)