mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
commit
a6b4c2beea
4 changed files with 15 additions and 1 deletions
|
|
@ -116,7 +116,7 @@ class Avatar(models.Model):
|
|||
else:
|
||||
diff = int((h - w) / 2)
|
||||
image = image.crop((0, diff, w, h - diff))
|
||||
if image.mode != "RGB":
|
||||
if image.mode not in ("RGB", "RGBA"):
|
||||
image = image.convert("RGB")
|
||||
image = image.resize((size, size), settings.AVATAR_RESIZE_METHOD)
|
||||
thumb = six.BytesIO()
|
||||
|
|
|
|||
BIN
tests/data/django.png
Normal file
BIN
tests/data/django.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
tests/data/django_pony_cmyk.jpg
Normal file
BIN
tests/data/django_pony_cmyk.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
|
|
@ -3,6 +3,7 @@ import os.path
|
|||
from django.contrib.admin.sites import AdminSite
|
||||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from avatar.admin import AvatarAdmin
|
||||
from avatar.conf import settings
|
||||
|
|
@ -164,3 +165,16 @@ class AvatarTests(TestCase):
|
|||
# def testChangePrimaryAvatar
|
||||
# def testDeleteThumbnailAndRecreation
|
||||
# def testAutomaticThumbnailCreation
|
||||
|
||||
@override_settings(AVATAR_THUMB_FORMAT='png')
|
||||
def testAutomaticThumbnailCreationRGBA(self):
|
||||
upload_helper(self, "django.png")
|
||||
avatar = get_primary_avatar(self.user)
|
||||
image = Image.open(avatar.avatar.storage.open(avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), 'rb'))
|
||||
self.assertEqual(image.mode, 'RGBA')
|
||||
|
||||
def testAutomaticThumbnailCreationCMYK(self):
|
||||
upload_helper(self, "django_pony_cmyk.jpg")
|
||||
avatar = get_primary_avatar(self.user)
|
||||
image = Image.open(avatar.avatar.storage.open(avatar.avatar_name(settings.AVATAR_DEFAULT_SIZE), 'rb'))
|
||||
self.assertEqual(image.mode, 'RGB')
|
||||
|
|
|
|||
Loading…
Reference in a new issue