Fix get attr exif problems
This commit is contained in:
parent
f70b347bd6
commit
534e4b884b
2 changed files with 16 additions and 20 deletions
22
edit.py
22
edit.py
|
@ -30,6 +30,7 @@ def dms_coordinates_to_dd_coordinates(coordinates, coordinates_ref):
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
def __init__(self, path, w=1920, h=1080):
|
def __init__(self, path, w=1920, h=1080):
|
||||||
|
print("editing", path)
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -43,11 +44,13 @@ class Image:
|
||||||
return e
|
return e
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_place_name(self, e):
|
def get_place_name(self, e):
|
||||||
lat = str(dms_coordinates_to_dd_coordinates(e['gps_latitude'], e['gps_latitude_ref']))
|
elat = e.get('gps_latitude', None)
|
||||||
lng = str(dms_coordinates_to_dd_coordinates(e['gps_longitude'], e['gps_longitude_ref']))
|
elng = e.get('gps_longitude', None)
|
||||||
if lat and lng:
|
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")
|
location = self.geolocator.reverse(lat + ", " + lng, language="en")
|
||||||
city = location.raw.get('address', {}).get('city', "")
|
city = location.raw.get('address', {}).get('city', "")
|
||||||
country = location.raw.get('address', {}).get('country', "")
|
country = location.raw.get('address', {}).get('country', "")
|
||||||
|
@ -107,11 +110,14 @@ class Image:
|
||||||
def add_metadata(self):
|
def add_metadata(self):
|
||||||
e = self.get_exif()
|
e = self.get_exif()
|
||||||
if e:
|
if e:
|
||||||
d = datetime.strptime(e['datetime_original'], "%Y:%m:%d %H:%M:%S")
|
dt = e.get('datetime_original', e.get('datetime', None))
|
||||||
date = d.strftime("%Y-%m-%d %H:%M")
|
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)
|
place = self.get_place_name(e)
|
||||||
self.writeText(date, 2)
|
if place:
|
||||||
self.writeText(place, 1)
|
self.writeText(place, 1)
|
||||||
|
|
||||||
def writeText(self, text, line_from_bottom):
|
def writeText(self, text, line_from_bottom):
|
||||||
WHITE = (255, 255, 255)
|
WHITE = (255, 255, 255)
|
||||||
|
|
14
ha.py
14
ha.py
|
@ -5,17 +5,6 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import edit
|
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):
|
def new_path(i, path):
|
||||||
return os.path.join(os.path.dirname(path), str(i) + '.jpg')
|
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)
|
n_path = new_path(i, path)
|
||||||
img = edit.Image(path)
|
img = edit.Image(path)
|
||||||
img.crop()
|
img.crop()
|
||||||
|
img.add_metadata()
|
||||||
img.safe(n_path)
|
img.safe(n_path)
|
||||||
return n_path
|
return n_path
|
||||||
|
|
||||||
|
@ -35,7 +25,7 @@ if __name__ == "__main__":
|
||||||
ha_path = "root@bundang.swierczyniec.info:/media/Synology"
|
ha_path = "root@bundang.swierczyniec.info:/media/Synology"
|
||||||
host_ip = os.getenv('DB_HOST')
|
host_ip = os.getenv('DB_HOST')
|
||||||
conn = synology.connect_db(host_ip, os.getenv('DB_USER'), os.getenv('DB_PASSWD'))
|
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)
|
pictures = synology.fetch_paths_for_names(conn, names, 20)
|
||||||
synology.close_db(conn)
|
synology.close_db(conn)
|
||||||
dirpath = synology.fetch_files("jeena@" + host_ip, "/var/services/homes/jeena/Photos", pictures)
|
dirpath = synology.fetch_files("jeena@" + host_ip, "/var/services/homes/jeena/Photos", pictures)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue