aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/exif.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/tools/exif.py')
-rw-r--r--mediagoblin/tools/exif.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/mediagoblin/tools/exif.py b/mediagoblin/tools/exif.py
index 448a342e..c4fc1fe5 100644
--- a/mediagoblin/tools/exif.py
+++ b/mediagoblin/tools/exif.py
@@ -32,6 +32,7 @@ USEFUL_TAGS = [
'EXIF UserComment',
]
+
def exif_image_needs_rotation(exif_tags):
"""
Returns True if EXIF orientation requires rotation
@@ -39,6 +40,7 @@ def exif_image_needs_rotation(exif_tags):
return 'Image Orientation' in exif_tags \
and exif_tags['Image Orientation'].values[0] != 1
+
def exif_fix_image_orientation(im, exif_tags):
"""
Translate any EXIF orientation to raw orientation
@@ -47,7 +49,7 @@ def exif_fix_image_orientation(im, exif_tags):
- REDUCES IMAGE QUALITY by recompressig it
Pros:
- - Cures my neck pain
+ - Prevents neck pain
"""
# Rotate image
if 'Image Orientation' in exif_tags:
@@ -62,6 +64,7 @@ def exif_fix_image_orientation(im, exif_tags):
return im
+
def extract_exif(filename):
"""
Returns EXIF tags found in file at ``filename``
@@ -76,6 +79,7 @@ def extract_exif(filename):
return exif_tags
+
def clean_exif(exif):
'''
Clean the result from anything the database cannot handle
@@ -96,6 +100,7 @@ def clean_exif(exif):
return clean_exif
+
def _ifd_tag_to_dict(tag):
data = {
'printable': tag.printable,
@@ -117,9 +122,11 @@ def _ifd_tag_to_dict(tag):
return data
+
def _ratio_to_list(ratio):
return [ratio.num, ratio.den]
+
def get_useful(tags):
useful = {}
for key, tag in tags.items():
@@ -127,7 +134,7 @@ def get_useful(tags):
useful[key] = tag
return useful
-
+
def get_gps_data(tags):
"""
@@ -147,9 +154,13 @@ def get_gps_data(tags):
gps_data[key] = (
lambda v:
float(v[0].num) / float(v[0].den) \
- + (float(v[1].num) / float(v[1].den) / 60 )\
+ + (float(v[1].num) / float(v[1].den) / 60) \
+ (float(v[2].num) / float(v[2].den) / (60 * 60))
)(dat.values)
+
+ if tags['GPS GPSLongitudeRef'].values == 'W':
+ gps_data['longitude'] /= -1
+
except KeyError:
pass