Fix get attr exif problems

This commit is contained in:
Jeena 2021-09-08 06:03:41 +02:00
parent f70b347bd6
commit 534e4b884b
2 changed files with 16 additions and 20 deletions

16
edit.py
View file

@ -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
@ -45,9 +46,11 @@ class Image:
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,10 +110,13 @@ class Image:
def add_metadata(self):
e = self.get_exif()
if e:
d = datetime.strptime(e['datetime_original'], "%Y:%m:%d %H:%M:%S")
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")
place = self.get_place_name(e)
self.writeText(date, 2)
place = self.get_place_name(e)
if place:
self.writeText(place, 1)
def writeText(self, text, line_from_bottom):

14
ha.py
View file

@ -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)