mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Better handle rotations
This commit is contained in:
@ -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 %}
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user