mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Correct thumbnail transposing for Safari, resolves #207
This commit is contained in:
parent
8475d37c2a
commit
0e09d40bf1
2 changed files with 6 additions and 23 deletions
|
|
@ -6,6 +6,7 @@ Changelog
|
|||
* Made ``True`` the default value of ``AVATAR_CLEANUP_DELETED``. (Set to ``False`` to obtain previous behavior).
|
||||
* Fix invalidate_cache for on-the-fly created thumbnails.
|
||||
* New setting ``AVATAR_ALLOWED_MIMETYPES``. If enabled, it checks mimetypes of uploaded files using ``python-magic``. Default is ``None``.
|
||||
* Fix thumbnail transposing for Safari.
|
||||
|
||||
* 6.0.1 (August 12, 2022)
|
||||
* Exclude tests folder from distribution.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from django.utils.encoding import force_str
|
|||
from django.utils.module_loading import import_string
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
from avatar.conf import settings
|
||||
from avatar.utils import force_bytes, get_username, invalidate_cache
|
||||
|
|
@ -122,28 +122,10 @@ class Avatar(models.Model):
|
|||
return self.avatar.storage.exists(self.avatar_name(width, height))
|
||||
|
||||
def transpose_image(self, image):
|
||||
"""
|
||||
Transpose based on EXIF information.
|
||||
Borrowed from django-imagekit:
|
||||
imagekit.processors.Transpose
|
||||
"""
|
||||
EXIF_ORIENTATION_STEPS = {
|
||||
1: [],
|
||||
2: ["FLIP_LEFT_RIGHT"],
|
||||
3: ["ROTATE_180"],
|
||||
4: ["FLIP_TOP_BOTTOM"],
|
||||
5: ["ROTATE_270", "FLIP_LEFT_RIGHT"],
|
||||
6: ["ROTATE_270"],
|
||||
7: ["ROTATE_90", "FLIP_LEFT_RIGHT"],
|
||||
8: ["ROTATE_90"],
|
||||
}
|
||||
try:
|
||||
orientation = image._getexif()[0x0112]
|
||||
ops = EXIF_ORIENTATION_STEPS[orientation]
|
||||
except (AttributeError, TypeError):
|
||||
ops = []
|
||||
for method in ops:
|
||||
image = image.transpose(getattr(Image, method))
|
||||
EXIF_ORIENTATION = 0x0112
|
||||
exif_code = image.getexif().get(EXIF_ORIENTATION, 1)
|
||||
if exif_code and exif_code != 1:
|
||||
image = ImageOps.exif_transpose(image)
|
||||
return image
|
||||
|
||||
def create_thumbnail(self, width, height=None, quality=None):
|
||||
|
|
|
|||
Loading…
Reference in a new issue