Add updating exif info
This commit is contained in:
parent
77d4b2e9c4
commit
6deb7c28b9
1 changed files with 19 additions and 5 deletions
|
@ -70,13 +70,15 @@ class image_classifier:
|
|||
self._log.debug(f"Found {len(people)} known people in the image.")
|
||||
self._log.debug(json.dumps(people, indent=2))
|
||||
with open(file, 'rb') as image_file:
|
||||
exif_info = exif.Image(image_file)
|
||||
if exif_info.has_exif:
|
||||
for key in exif_info.list_all():
|
||||
self.exif_info = exif.Image(image_file)
|
||||
if self.exif_info.has_exif:
|
||||
for key in self.exif_info.list_all():
|
||||
if key != 'cannot read a base/unknown IFD tag instance':
|
||||
sys.stdout.write(f"{key}: ")
|
||||
sys.stdout.write(exif_info[key])
|
||||
#exif_info["user_comment"]
|
||||
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.")
|
||||
# get date
|
||||
|
@ -84,6 +86,18 @@ class image_classifier:
|
|||
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']):
|
||||
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['PeopleDetected'] = list()
|
||||
for person in people:
|
||||
data['PeopleDetected'].append(person)
|
||||
self.exif_info["user_comment"] = json.dumps(data)
|
||||
|
||||
def is_json(self, data):
|
||||
result = json.loads(data)
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue