Fix problem with non existent address
In addition increase padding for text, put date at bottom if there is no address.
This commit is contained in:
parent
22ce50a493
commit
d039dd1cc2
1 changed files with 16 additions and 11 deletions
27
edit.py
27
edit.py
|
@ -52,12 +52,13 @@ class Image:
|
||||||
lat = str(dms_coordinates_to_dd_coordinates(elat, e['gps_latitude_ref']))
|
lat = str(dms_coordinates_to_dd_coordinates(elat, e['gps_latitude_ref']))
|
||||||
lng = str(dms_coordinates_to_dd_coordinates(elng, e['gps_longitude_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', "")
|
if location:
|
||||||
country = location.raw.get('address', {}).get('country', "")
|
city = location.raw.get('address', {}).get('city', None)
|
||||||
name = ", ".join((city, country))
|
country = location.raw.get('address', {}).get('country', None)
|
||||||
return name
|
name = ", ".join(list(filter(lambda x: x, [city, country])))
|
||||||
else:
|
if name != "":
|
||||||
return ""
|
return name
|
||||||
|
return None
|
||||||
|
|
||||||
def crop(self):
|
def crop(self):
|
||||||
oh, ow, z = self.image.shape
|
oh, ow, z = self.image.shape
|
||||||
|
@ -110,14 +111,18 @@ class Image:
|
||||||
def add_metadata(self):
|
def add_metadata(self):
|
||||||
e = self.get_exif()
|
e = self.get_exif()
|
||||||
if e:
|
if e:
|
||||||
|
line = 1
|
||||||
dt = e.get('datetime_original', e.get('datetime', None))
|
dt = e.get('datetime_original', e.get('datetime', None))
|
||||||
|
place = self.get_place_name(e)
|
||||||
|
if place:
|
||||||
|
self.writeText(place, line)
|
||||||
|
line += 1
|
||||||
if dt:
|
if dt:
|
||||||
d = datetime.strptime(dt, "%Y:%m:%d %H:%M:%S")
|
d = datetime.strptime(dt, "%Y:%m:%d %H:%M:%S")
|
||||||
date = d.strftime("%Y-%m-%d %H:%M")
|
date = d.strftime("%Y-%m-%d %H:%M")
|
||||||
self.writeText(date, 2)
|
self.writeText(date, line)
|
||||||
place = self.get_place_name(e)
|
line += 1
|
||||||
if place:
|
|
||||||
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)
|
||||||
|
@ -127,7 +132,7 @@ class Image:
|
||||||
font_color = BLACK
|
font_color = BLACK
|
||||||
font_thickness = 4
|
font_thickness = 4
|
||||||
line_height = 1.2
|
line_height = 1.2
|
||||||
padding = 20
|
padding = 50
|
||||||
textsize, baseline = cv2.getTextSize(text, font, font_size, font_thickness)
|
textsize, baseline = cv2.getTextSize(text, font, font_size, font_thickness)
|
||||||
x = self.image.shape[1] - textsize[0] - padding
|
x = self.image.shape[1] - textsize[0] - padding
|
||||||
y = int(self.image.shape[0] - textsize[1] * line_from_bottom * line_height + baseline - padding)
|
y = int(self.image.shape[0] - textsize[1] * line_from_bottom * line_height + baseline - padding)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue