From: Joar Wandborg Date: Sat, 23 Jun 2012 15:21:22 +0000 (+0200) Subject: Fixed EXIF longitude bug X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c72d661bed5d83d952dc2361a86dfe40ff435c54;p=mediagoblin.git Fixed EXIF longitude bug - Negative or 'W' longitudes were not accounted for. - pyflakes fixes. --- diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index bbfcd32d..487d593a 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -30,7 +30,8 @@ _log = logging.getLogger(__name__) def resize_image(entry, filename, new_path, exif_tags, workdir, new_size, size_limits=(0, 0)): - """Store a resized version of an image and return its pathname. + """ + Store a resized version of an image and return its pathname. Arguments: entry -- the entry for the image to resize 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