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( diff --git a/ivatar/views.py b/ivatar/views.py index 387c42c..a50b571 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,16 @@ class AvatarImageView(TemplateView): data, content_type='image/png') + if str(default) == 'pagan': + paganobj = pagan.Avatar(kwargs['digest']) + data = BytesIO() + img = paganobj.img.resize((size, size), Image.ANTIALIAS) + 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