Translate any EXIF orientation to raw orientation
Cons:
- - REDUCES IMAGE QUALITY by recompressing it
+ - Well, it changes the image, which means we'll recompress
+ it... not a problem if scaling it down already anyway. We might
+ lose some quality in recompressing if it's at the same-size
+ though
Pros:
- Prevents neck pain
"""
Returns EXIF tags found in file at ``filename``
"""
- exif_tags = {}
-
try:
- image = open(filename)
- exif_tags = process_file(image, details=False)
+ with file(filename) as image:
+ return process_file(image, details=False)
except IOError:
raise BadMediaFail(_('Could not read the image file.'))
- return exif_tags
-
def clean_exif(exif):
'''
'JPEGThumbnail',
'Thumbnail JPEGInterchangeFormat']
- clean_exif = {}
-
- for key, value in exif.items():
- if not key in disabled_tags:
- clean_exif[key] = _ifd_tag_to_dict(value)
- return clean_exif
+ return dict((key, _ifd_tag_to_dict(value)) for (key, value)
+ in exif.iteritems() if key not in disabled_tags)
def _ifd_tag_to_dict(tag):
data['printable'] = tag.printable.decode('utf8', 'replace')
if type(tag.values) == list:
- data['values'] = []
- for val in tag.values:
- if isinstance(val, Ratio):
- data['values'].append(
- _ratio_to_list(val))
- else:
- data['values'].append(val)
+ data['values'] = [_ratio_to_list(val) if isinstance(val, Ratio) else val
+ for val in tag.values]
else:
if isinstance(tag.values, str):
# Force UTF-8, so that it fits into the DB
def get_useful(tags):
- useful = {}
- for key, tag in tags.items():
- if key in USEFUL_TAGS:
- useful[key] = tag
-
- return useful
+ return dict((key, tag) for (key, tag) in tags.iteritems())
def get_gps_data(tags):
'latitude': tags['GPS GPSLatitude'],
'longitude': tags['GPS GPSLongitude']}
- for key, dat in dms_data.items():
+ for key, dat in dms_data.iteritems():
gps_data[key] = (
lambda v:
float(v[0].num) / float(v[0].den) \