Remove exif
This commit is contained in:
parent
e01390fa3f
commit
95b611e61f
1 changed files with 13 additions and 23 deletions
|
@ -70,42 +70,32 @@ class image_classifier:
|
|||
if people:
|
||||
self._log.debug(f"Found {len(people)} known people in the image.")
|
||||
self._log.debug(json.dumps(people, indent=2))
|
||||
iptc_info = IPTCInfo(file, force=True)
|
||||
print(iptc_info['keywords'])
|
||||
with open(file, 'rb') as image_file:
|
||||
self.exif_info = exif.Image(image_file)
|
||||
if not self.exif_info.has_exif:
|
||||
self._log.debug("No exif info in the image.")
|
||||
else:
|
||||
# for key in dir(self.exif_info):
|
||||
# if not key.startswith("_"):
|
||||
# sys.stdout.write(f"{key}: ")
|
||||
# sys.stdout.write(f"{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())
|
||||
self.iptc_info = IPTCInfo(file, force=True)
|
||||
print(self.iptc_info['keywords'])
|
||||
self.append_people(people)
|
||||
self.iptc_info.save()
|
||||
self._log.debug(f"Updated file '{file}'.")
|
||||
# get date
|
||||
self._log.debug(f"File time stamp: {self.exif_info.get('Image timestamp')} (type: {type(self.exif_info.get('Image timestamp'))})")
|
||||
self._log.debug(f"File time stamp: {self.iptc_info.get('Image timestamp')} (type: {type(self.exif_info.get('Image timestamp'))})")
|
||||
# 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.get('user_comment')):
|
||||
data = json.loads(self.exif_info['user_comment'])
|
||||
if self.is_json(self.iptc_info.get('user_comment')):
|
||||
data = json.loads(self.iptc_info['user_comment'])
|
||||
if 'PeopleDetected' not in data:
|
||||
data['PeopleDetected'] = list()
|
||||
else:
|
||||
data = dict()
|
||||
if self.exif_info.get('user_comment'):
|
||||
data["previous_user_comment"]=self.exif_info.get('user_comment')
|
||||
if self.exif_iptc_infoinfo.get('user_comment'):
|
||||
data["previous_user_comment"]=self.iptc_info.get('user_comment')
|
||||
data['PeopleDetected'] = list()
|
||||
for person in people:
|
||||
if person not in data['PeopleDetected']:
|
||||
data['PeopleDetected'].append(person)
|
||||
self._log.debug(f"New 'user_comment': {json.dumps(data, indent=2)}")
|
||||
self.exif_info.set("user_comment", json.dumps(data))
|
||||
self.iptc_info.set("user_comment", json.dumps(data))
|
||||
|
||||
def is_json(self, data):
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue