Better handle rotations

This commit is contained in:
Skia
2016-11-20 13:39:04 +01:00
parent 869634d6e1
commit 815ef03860
6 changed files with 55 additions and 10 deletions

View File

@ -12,7 +12,7 @@
{% for r in user.pictures.exclude(picture=None).filter(picture__parent=album) %}
<div style="display: inline-block; border: solid 1px black; width: 9%; margin: 0.1%">
<a href="{{ url("sas:picture", picture_id=r.picture.id) }}#pict">
<img src="{{ r.picture.as_picture.get_download_url() }}" alt="{{ r.picture.get_display_name() }}" style="max-width: 100%"/>
<img src="{{ r.picture.as_picture.get_download_thumb_url() }}" alt="{{ r.picture.get_display_name() }}" style="max-width: 100%"/>
</a>
</div>
{% endfor %}

View File

@ -1,7 +1,7 @@
# Image utils
from io import BytesIO
from PIL import Image
from PIL import Image, ExifTags
# from exceptions import IOError
import PIL
from django.core.files.base import ContentFile
@ -25,3 +25,16 @@ def resize_image(im, edge, format):
im.save(fp=content, format=format.upper(), quality=90, optimize=True, progressive=True)
return ContentFile(content.getvalue())
def exif_auto_rotate(image):
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)
return image