diff --git a/rowers/rows.py b/rowers/rows.py index 720fd710..6aa7401a 100644 --- a/rowers/rows.py +++ b/rowers/rows.py @@ -90,15 +90,9 @@ def handle_uploaded_image(i): break exif=dict(image._getexif().items()) - if exif[orientation] == 3: - image=image.rotate(180, expand=True) - elif exif[orientation] == 6: - image=image.rotate(270, expand=True) - elif exif[orientation] == 8: - image=image.rotate(90, expand=True) except (AttributeError, KeyError, IndexError): # cases: image don't have getexif - pass + exif = {'orientation':0} if image.mode not in ("L", "RGB"): image = image.convert("RGB") @@ -108,6 +102,12 @@ def handle_uploaded_image(i): hsize = int((float(image.size[1])*float(wpercent))) image = image.resize((basewidth,hsize), Image.ANTIALIAS) + if exif[orientation] == 3: + image=image.rotate(180, expand=True) + elif exif[orientation] == 6: + image=image.rotate(270, expand=True) + elif exif[orientation] == 8: + image=image.rotate(90, expand=True) filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'