Merge branch 'feature/rotate' into develop
This commit is contained in:
@@ -72,15 +72,34 @@ def must_be_csv(value):
|
|||||||
|
|
||||||
def handle_uploaded_image(i):
|
def handle_uploaded_image(i):
|
||||||
import StringIO
|
import StringIO
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps, ExifTags
|
||||||
import os
|
import os
|
||||||
from django.core.files import File
|
from django.core.files import File
|
||||||
image_str = ""
|
image_str = ""
|
||||||
for c in i.chunks():
|
for chunk in i.chunks():
|
||||||
image_str += c
|
image_str += chunk
|
||||||
imagefile = StringIO.StringIO(image_str)
|
|
||||||
image = Image.open(imagefile)
|
|
||||||
|
|
||||||
|
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())
|
||||||
|
|
||||||
|
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"):
|
if image.mode not in ("L", "RGB"):
|
||||||
image = image.convert("RGB")
|
image = image.convert("RGB")
|
||||||
|
|
||||||
@@ -89,12 +108,12 @@ def handle_uploaded_image(i):
|
|||||||
hsize = int((float(image.size[1])*float(wpercent)))
|
hsize = int((float(image.size[1])*float(wpercent)))
|
||||||
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
|
image = image.resize((basewidth,hsize), Image.ANTIALIAS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'
|
filename = hashlib.md5(imagefile.getvalue()).hexdigest()+'.jpg'
|
||||||
|
|
||||||
filename2 = os.path.join('static/plots/',filename)
|
filename2 = os.path.join('static/plots/',filename)
|
||||||
image.save(filename2,'JPEG')
|
image.save(filename2,'JPEG')
|
||||||
|
|
||||||
return filename,filename2
|
return filename,filename2
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8898,7 +8898,7 @@ def workout_uploadimage_view(request,id):
|
|||||||
url = reverse(r.defaultlandingpage,
|
url = reverse(r.defaultlandingpage,
|
||||||
kwargs = {'id':id})
|
kwargs = {'id':id})
|
||||||
if is_ajax:
|
if is_ajax:
|
||||||
return JSONResponse({'result':1,'url':0})
|
return JSONResponse({'result':1,'url':url})
|
||||||
else:
|
else:
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user