From c9774113098c84c37f663fdbac44066763779686 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Thu, 28 Feb 2019 14:14:10 +0100 Subject: [PATCH 1/3] Fix issue #49 --- ivatar/ivataraccount/models.py | 6 +++--- ivatar/ivataraccount/test_views.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ivatar/ivataraccount/models.py b/ivatar/ivataraccount/models.py index 1200666..05b2137 100644 --- a/ivatar/ivataraccount/models.py +++ b/ivatar/ivataraccount/models.py @@ -37,10 +37,10 @@ from .gravatar import get_photo as get_gravatar_photo def file_format(image_type): ''' - Helper method returning a 3 character long image type + Helper method returning a short image type ''' if image_type == 'JPEG': - return 'jpg' + return 'jpeg' elif image_type == 'PNG': return 'png' elif image_type == 'GIF': @@ -52,7 +52,7 @@ def pil_format(image_type): ''' Helper method returning the 'encoder name' for PIL ''' - if image_type == 'jpg': + if image_type == 'jpg' or image_type == 'jpeg': return 'JPEG' elif image_type == 'png': return 'PNG' diff --git a/ivatar/ivataraccount/test_views.py b/ivatar/ivataraccount/test_views.py index 1058980..57ab8dc 100644 --- a/ivatar/ivataraccount/test_views.py +++ b/ivatar/ivataraccount/test_views.py @@ -358,7 +358,7 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods # Probably not the best way to access the content type self.assertEqual( response['Content-Type'], - 'image/jpg', + 'image/jpeg', 'Content type wrong!?') self.assertEqual( @@ -638,10 +638,10 @@ class Tester(TestCase): # pylint: disable=too-many-public-methods self.assertEqual( str(list(response.context[0]['messages'])[0]), 'Successfully uploaded', - 'JPG upload failed?!') + 'JPEG upload failed?!') self.assertEqual( - self.user.photo_set.first().format, 'jpg', - 'Format must be jpg, since we uploaded a jpg!') + self.user.photo_set.first().format, 'jpeg', + 'Format must be jpeg, since we uploaded a jpeg!') self.test_confirm_email() self.user.confirmedemail_set.first().photo = self.user.photo_set.first() urlobj = urlsplit( From 2d62e658e4cd5b0bd666211f3c0f91325389ac22 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Thu, 28 Feb 2019 17:02:15 +0100 Subject: [PATCH 2/3] Implement the pagan lib (for fun) --- ivatar/views.py | 11 ++++++++++- requirements.txt | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ivatar/views.py b/ivatar/views.py index 387c42c..4f56b43 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -18,7 +18,7 @@ from PIL import Image from monsterid.id import build_monster as BuildMonster import Identicon from pydenticon5 import Pydenticon5 - +import pagan from robohash import Robohash from ivatar.settings import AVATAR_MAX_SIZE, JPEG_QUALITY, DEFAULT_AVATAR_SIZE @@ -166,6 +166,15 @@ class AvatarImageView(TemplateView): data, content_type='image/png') + if str(default) == 'pagan': + img = pagan.Avatar(kwargs['digest']) + data = BytesIO() + img.img.save(data, 'PNG', quality=JPEG_QUALITY) + data.seek(0) + return HttpResponse( + data, + content_type='image/png') + if str(default) == 'identicon': p = Pydenticon5() # In order to make use of the whole 32 bytes digest, we need to redigest them. diff --git a/requirements.txt b/requirements.txt index 9a9a4dc..d2bdc99 100644 --- a/requirements.txt +++ b/requirements.txt @@ -37,3 +37,4 @@ git+https://github.com/ofalk/Robohash.git@devel python-memcached git+https://github.com/ercpe/pydenticon5.git git+https://github.com/flavono123/identicon.git +pagan From 60fbf93a4f2c897ad7d0c72f86ae39994de65129 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Thu, 28 Feb 2019 17:15:04 +0100 Subject: [PATCH 3/3] Make sure we do the pagan avatar in the right size --- ivatar/views.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ivatar/views.py b/ivatar/views.py index 4f56b43..a50b571 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -167,9 +167,10 @@ class AvatarImageView(TemplateView): content_type='image/png') if str(default) == 'pagan': - img = pagan.Avatar(kwargs['digest']) + paganobj = pagan.Avatar(kwargs['digest']) data = BytesIO() - img.img.save(data, 'PNG', quality=JPEG_QUALITY) + img = paganobj.img.resize((size, size), Image.ANTIALIAS) + img.save(data, 'PNG', quality=JPEG_QUALITY) data.seek(0) return HttpResponse( data,