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:
|
if people:
|
||||||
self._log.debug(f"Found {len(people)} known people in the image.")
|
self._log.debug(f"Found {len(people)} known people in the image.")
|
||||||
self._log.debug(json.dumps(people, indent=2))
|
self._log.debug(json.dumps(people, indent=2))
|
||||||
iptc_info = IPTCInfo(file, force=True)
|
self.iptc_info = IPTCInfo(file, force=True)
|
||||||
print(iptc_info['keywords'])
|
print(self.iptc_info['keywords'])
|
||||||
with open(file, 'rb') as image_file:
|
self.append_people(people)
|
||||||
self.exif_info = exif.Image(image_file)
|
self.iptc_info.save()
|
||||||
if not self.exif_info.has_exif:
|
self._log.debug(f"Updated file '{file}'.")
|
||||||
self._log.debug("No exif info in the image.")
|
# get date
|
||||||
else:
|
self._log.debug(f"File time stamp: {self.iptc_info.get('Image timestamp')} (type: {type(self.exif_info.get('Image timestamp'))})")
|
||||||
# for key in dir(self.exif_info):
|
# move to destination
|
||||||
# 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._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'))})")
|
|
||||||
# move to destination
|
|
||||||
else:
|
else:
|
||||||
self._log.debug("Doesn't seem to be an image.")
|
self._log.debug("Doesn't seem to be an image.")
|
||||||
|
|
||||||
def append_people_to_exif(self, people):
|
def append_people_to_exif(self, people):
|
||||||
if self.is_json(self.exif_info.get('user_comment')):
|
if self.is_json(self.iptc_info.get('user_comment')):
|
||||||
data = json.loads(self.exif_info['user_comment'])
|
data = json.loads(self.iptc_info['user_comment'])
|
||||||
if 'PeopleDetected' not in data:
|
if 'PeopleDetected' not in data:
|
||||||
data['PeopleDetected'] = list()
|
data['PeopleDetected'] = list()
|
||||||
else:
|
else:
|
||||||
data = dict()
|
data = dict()
|
||||||
if self.exif_info.get('user_comment'):
|
if self.exif_iptc_infoinfo.get('user_comment'):
|
||||||
data["previous_user_comment"]=self.exif_info.get('user_comment')
|
data["previous_user_comment"]=self.iptc_info.get('user_comment')
|
||||||
data['PeopleDetected'] = list()
|
data['PeopleDetected'] = list()
|
||||||
for person in people:
|
for person in people:
|
||||||
if person not in data['PeopleDetected']:
|
if person not in data['PeopleDetected']:
|
||||||
data['PeopleDetected'].append(person)
|
data['PeopleDetected'].append(person)
|
||||||
self._log.debug(f"New 'user_comment': {json.dumps(data, indent=2)}")
|
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):
|
def is_json(self, data):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue