# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
from mediagoblin.processing import BadMediaFail
from mediagoblin.tools.translate import pass_to_ugettext as _
-from collections import OrderedDict
-
# A list of tags that should be stored for faster access
USEFUL_TAGS = [
'Image Make',
'EXIF UserComment',
]
+
+def exif_image_needs_rotation(exif_tags):
+ """
+ Returns True if EXIF orientation requires rotation
+ """
+ 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
- REDUCES IMAGE QUALITY by recompressig it
Pros:
- - Cures my neck pain
+ - Prevents neck pain
"""
# Rotate image
if 'Image Orientation' in exif_tags:
return im
+
def extract_exif(filename):
"""
Returns EXIF tags found in file at ``filename``
return exif_tags
+
def clean_exif(exif):
'''
- Clean the result from anyt
-hing the database cannot handle
+ Clean the result from anything the database cannot handle
'''
# Discard any JPEG thumbnail, for database compatibility
# and that I cannot see a case when we would use it.
return clean_exif
+
def _ifd_tag_to_dict(tag):
data = {
'printable': tag.printable,
return data
+
def _ratio_to_list(ratio):
return [ratio.num, ratio.den]
+
def get_useful(tags):
useful = {}
for key, tag in tags.items():
useful[key] = tag
return useful
-
+
def get_gps_data(tags):
"""
Processes EXIF data returned by EXIF.py
"""
- if not 'Image GPSInfo' in tags:
- return False
-
gps_data = {}
+ if not 'Image GPSInfo' in tags:
+ return gps_data
+
try:
dms_data = {
'latitude': tags['GPS GPSLatitude'],
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