aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Rossi <alexandre.rossi@gmail.com>2019-07-05 12:46:55 +0200
committerAlexandre Rossi <alexandre.rossi@gmail.com>2019-07-05 12:46:55 +0200
commit51f655ff2f6bfea71d5762f4d4908b5e921b402d (patch)
tree008dde41fcca95208e6973b5a286a9f417fafe26
parent323ffd8337bdff5070385cc49e59b8dd07651cf1 (diff)
downloadlazygal-51f655ff2f6bfea71d5762f4d4908b5e921b402d.zip
lazygal-51f655ff2f6bfea71d5762f4d4908b5e921b402d.tar.bz2
show GPS data from EXIFHEADmaster
-rw-r--r--lazygal/metadata.py14
-rw-r--r--lazygal/tplvars.py3
-rw-r--r--lazygaltest/test_metadata.py15
-rw-r--r--themes/nojs/image.thtml1
4 files changed, 33 insertions, 0 deletions
diff --git a/lazygal/metadata.py b/lazygal/metadata.py
index f102160..4ad2079 100644
--- a/lazygal/metadata.py
+++ b/lazygal/metadata.py
@@ -419,6 +419,20 @@ class ImageInfoTags(object):
return kw
+ def get_location(self):
+ loc = self._metadata.get_gps_info()
+ if loc == (0, 0, 0):
+ return None
+ else:
+ return {
+ # https://xkcd.com/2170/
+ 'latitude': round(loc.latitude, 4),
+ 'latitudeRef': self._metadata['Exif.GPSInfo.GPSLatitudeRef'],
+ 'longitude': round(loc.longitude, 4),
+ 'longitudeRef': self._metadata['Exif.GPSInfo.GPSLongitudeRef'],
+ 'altitude': round(loc.altitude),
+ }
+
def of_interest(self):
return { tag: self._metadata[tag]
for tag in TAGS_OF_INTEREST if tag in self._metadata }
diff --git a/lazygal/tplvars.py b/lazygal/tplvars.py
index a4d3d13..14a750f 100644
--- a/lazygal/tplvars.py
+++ b/lazygal/tplvars.py
@@ -125,6 +125,9 @@ class Image(Media):
tpl_values['authorship'] = image_info.get_authorship()
tpl_values['keywords'] = ', '.join(image_info.get_keywords())
+ if self.page.dir.config.get('webgal', 'keep-gps'):
+ tpl_values['location'] = image_info.get_location()
+
return tpl_values
diff --git a/lazygaltest/test_metadata.py b/lazygaltest/test_metadata.py
index 8d15898..bd4554a 100644
--- a/lazygaltest/test_metadata.py
+++ b/lazygaltest/test_metadata.py
@@ -247,6 +247,21 @@ Album image identifier "first\xe3.jpg"
])
)
+ def test_location(self):
+ sample = 'sample.jpg'
+ im_md = metadata.ImageInfoTags(self.get_sample_path(sample))
+ self.assertEqual(im_md.get_location(), None)
+
+ sample = 'sample-with-gps.jpg'
+ im_md = metadata.ImageInfoTags(self.get_sample_path(sample))
+ self.assertEqual(im_md.get_location(), {
+ 'latitude': 47.0636,
+ 'latitudeRef': 'N',
+ 'longitude': 8.6893,
+ 'longitudeRef': 'E',
+ 'altitude': 1527
+ })
+
if __name__ == '__main__':
unittest.main()
diff --git a/themes/nojs/image.thtml b/themes/nojs/image.thtml
index b977085..73485b9 100644
--- a/themes/nojs/image.thtml
+++ b/themes/nojs/image.thtml
@@ -22,6 +22,7 @@
<li py:if="fnumber">${_('Aperture')} $fnumber</li>
<li py:if="flash">${_('Flash')} $flash</li>
<li py:if="focal_length">${_('Focal length')} $focal_length</li>
+ <li py:if="location">${_('Location')} <a href="https://www.openstreetmap.org/?mlat=${location.latitude}&amp;mlon=${location.longitude}">$location.latitude $location.latitudeRef, $location.longitude $location.longitudeRef</a>, ${_('Altitude')} $location.altitude m</li>
</ul>
</div>
</div>