From 534e4b884b6298c87d58f54407e9e8cee1f69af0 Mon Sep 17 00:00:00 2001 From: Jeena Date: Wed, 8 Sep 2021 06:03:41 +0200 Subject: [PATCH] Fix get attr exif problems --- edit.py | 22 ++++++++++++++-------- ha.py | 14 ++------------ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/edit.py b/edit.py index 09cf6a4..b2200ab 100755 --- a/edit.py +++ b/edit.py @@ -30,6 +30,7 @@ def dms_coordinates_to_dd_coordinates(coordinates, coordinates_ref): class Image: def __init__(self, path, w=1920, h=1080): + print("editing", path) self.w = w self.h = h self.path = path @@ -43,11 +44,13 @@ class Image: return e else: return None - + def get_place_name(self, e): - lat = str(dms_coordinates_to_dd_coordinates(e['gps_latitude'], e['gps_latitude_ref'])) - lng = str(dms_coordinates_to_dd_coordinates(e['gps_longitude'], e['gps_longitude_ref'])) - if lat and lng: + elat = e.get('gps_latitude', None) + elng = e.get('gps_longitude', None) + if elat and elng: + lat = str(dms_coordinates_to_dd_coordinates(elat, e['gps_latitude_ref'])) + lng = str(dms_coordinates_to_dd_coordinates(elng, e['gps_longitude_ref'])) location = self.geolocator.reverse(lat + ", " + lng, language="en") city = location.raw.get('address', {}).get('city', "") country = location.raw.get('address', {}).get('country', "") @@ -107,11 +110,14 @@ class Image: def add_metadata(self): e = self.get_exif() if e: - d = datetime.strptime(e['datetime_original'], "%Y:%m:%d %H:%M:%S") - date = d.strftime("%Y-%m-%d %H:%M") + dt = e.get('datetime_original', e.get('datetime', None)) + if dt: + d = datetime.strptime(dt, "%Y:%m:%d %H:%M:%S") + date = d.strftime("%Y-%m-%d %H:%M") + self.writeText(date, 2) place = self.get_place_name(e) - self.writeText(date, 2) - self.writeText(place, 1) + if place: + self.writeText(place, 1) def writeText(self, text, line_from_bottom): WHITE = (255, 255, 255) diff --git a/ha.py b/ha.py index d60ef2d..d961495 100755 --- a/ha.py +++ b/ha.py @@ -5,17 +5,6 @@ import os import shutil import edit -def prepare_photo(i, path): - # sudo apt-get install ufraw-batch - # convert 13895032967_642e23af42_o.jpg -adaptive-resize 1920x1080\> -size 1920x1080 xc:black +swap -gravity center -composite 01.jpg - # filename, file_extension = os.path.splitext(path) - n_path = new_path(i, path) - cmd = 'convert "' + path + '" -adaptive-resize 1920x1080\> -size 1920x1080 xc:black +swap -gravity center -composite ' + n_path - print(cmd) - os.system(cmd) - # os.rename(path, new_path) - return n_path - def new_path(i, path): return os.path.join(os.path.dirname(path), str(i) + '.jpg') @@ -23,6 +12,7 @@ def resize_and_crop(i, path): n_path = new_path(i, path) img = edit.Image(path) img.crop() + img.add_metadata() img.safe(n_path) return n_path @@ -35,7 +25,7 @@ if __name__ == "__main__": ha_path = "root@bundang.swierczyniec.info:/media/Synology" host_ip = os.getenv('DB_HOST') conn = synology.connect_db(host_ip, os.getenv('DB_USER'), os.getenv('DB_PASSWD')) - names = "richard|yingfen" + names = "richard|yingfen|kaylee" pictures = synology.fetch_paths_for_names(conn, names, 20) synology.close_db(conn) dirpath = synology.fetch_files("jeena@" + host_ip, "/var/services/homes/jeena/Photos", pictures)