Private
Public Access
1
0

fixed EXIF rotations

This commit is contained in:
Sander Roosendaal
2018-01-23 21:22:44 +01:00
parent 28729c37d4
commit 58cdff8d0b
4 changed files with 28 additions and 7 deletions

1
rowers/.#rows.py Normal file
View File

@@ -0,0 +1 @@
E408191@CZ27LT9RCGN72.21668:1516641451

View File

@@ -72,15 +72,35 @@ def must_be_csv(value):
def handle_uploaded_image(i):
import StringIO
from PIL import Image, ImageOps
from PIL import Image, ImageOps, ExifTags
import os
from django.core.files import File
image_str = ""
for c in i.chunks():
image_str += c
imagefile = StringIO.StringIO(image_str)
image = Image.open(imagefile)
for chunk in i.chunks():
image_str += chunk
imagefile = StringIO.StringIO(image_str)
image = Image.open(i)
try:
for orientation in ExifTags.TAGS.keys():
if ExifTags.TAGS[orientation]=='Orientation':
break
exif=dict(image._getexif().items())
print exif[orientation],'aap'
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
if image.mode not in ("L", "RGB"):
image = image.convert("RGB")
@@ -89,12 +109,12 @@ def handle_uploaded_image(i):
hsize = int((float(image.size[1])*float(wpercent)))
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'
filename2 = os.path.join('static/plots/',filename)
image.save(filename2,'JPEG')
return filename,filename2

View File

@@ -8898,7 +8898,7 @@ def workout_uploadimage_view(request,id):
url = reverse(r.defaultlandingpage,
kwargs = {'id':id})
if is_ajax:
return JSONResponse({'result':1,'url':0})
return JSONResponse({'result':1,'url':url})
else:
return HttpResponseRedirect(url)
else:

BIN
temporary Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB