diff --git a/avatar/models.py b/avatar/models.py index 3557410..c64b21b 100644 --- a/avatar/models.py +++ b/avatar/models.py @@ -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() diff --git a/tests/data/django.png b/tests/data/django.png new file mode 100644 index 0000000..82474cb Binary files /dev/null and b/tests/data/django.png differ diff --git a/tests/data/django_pony_cmyk.jpg b/tests/data/django_pony_cmyk.jpg new file mode 100644 index 0000000..2712f77 Binary files /dev/null and b/tests/data/django_pony_cmyk.jpg differ diff --git a/tests/tests.py b/tests/tests.py index 64db82b..07c9f46 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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')