diff --git a/core/templates/core/user_pictures.jinja b/core/templates/core/user_pictures.jinja index e4cf9055..268edaed 100644 --- a/core/templates/core/user_pictures.jinja +++ b/core/templates/core/user_pictures.jinja @@ -12,7 +12,7 @@ {% for r in user.pictures.exclude(picture=None).filter(picture__parent=album) %}
{% endfor %} diff --git a/core/utils.py b/core/utils.py index 087cafa2..423c42b6 100644 --- a/core/utils.py +++ b/core/utils.py @@ -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 diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 9cb2df31..a407eda2 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -1950,7 +1950,7 @@ msgstr "Erreur de création du dossier %(folder_name)s : %(msg)s" #: sas/views.py:41 #, python-format msgid "Error uploading file %(file_name)s: %(msg)s" -msgstr "Erreur d'envoie du fichier %(file_name)s : %(msg)s" +msgstr "Erreur d'envoi du fichier %(file_name)s : %(msg)s" #: core/views/forms.py:59 core/views/forms.py:62 msgid "Choose file" diff --git a/sas/models.py b/sas/models.py index b8a9ee2f..e3f96318 100644 --- a/sas/models.py +++ b/sas/models.py @@ -30,6 +30,19 @@ class Picture(SithFile): def get_download_thumb_url(self): return reverse('sas:download_thumb', kwargs={'picture_id': self.id}) + def rotate(self, degree): + from PIL import Image + from io import BytesIO + from django.core.files.base import ContentFile + for attr in ['file', 'compressed', 'thumbnail']: + if self.__getattribute__(attr): + im = Image.open(BytesIO(self.__getattribute__(attr).read())) + new_image = BytesIO() + im = im.rotate(degree, expand=True) + im.save(fp=new_image, format=self.mime_type.split('/')[-1].upper(), quality=90, optimize=True, progressive=True) + self.__getattribute__(attr).save(self.name, ContentFile(new_image.getvalue())) + self.save() + def get_next(self): return self.parent.children.exclude(is_moderated=False, asked_for_removal=True).filter(id__gt=self.id).order_by('id').first() diff --git a/sas/templates/sas/picture.jinja b/sas/templates/sas/picture.jinja index b46b61bd..dc17a829 100644 --- a/sas/templates/sas/picture.jinja +++ b/sas/templates/sas/picture.jinja @@ -34,8 +34,12 @@ {% block content %} {{ print_path(picture.parent) }} {{ picture.get_display_name() }}