From 827477b47c959ce073c330fae89c86464220e127 Mon Sep 17 00:00:00 2001 From: Suneet Srivastava Date: Fri, 6 Dec 2019 00:22:24 +0530 Subject: [PATCH] fix: Image resizing performed using requests library --- app/api/helpers/files.py | 16 +++++++++++++--- docs/api/blueprint/user/users.apib | 12 ++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/api/helpers/files.py b/app/api/helpers/files.py index ede5e401fa..1b565aee0c 100644 --- a/app/api/helpers/files.py +++ b/app/api/helpers/files.py @@ -5,6 +5,7 @@ import urllib.parse import urllib.request import uuid +import requests import PIL from PIL import Image @@ -77,7 +78,7 @@ def create_save_resized_image(image_file, basewidth=None, maintain_aspect=None, if not image_file: return None filename = '{filename}.{ext}'.format(filename=get_file_name(), ext=ext) - data = urllib.request.urlopen(image_file).read() + data = requests.get(image_file).content image_file = io.BytesIO(data) try: im = Image.open(image_file) @@ -129,8 +130,17 @@ def create_save_image_sizes(image_file, image_sizes_type, unique_identifier=None try: image_sizes = ImageSizes.query.filter_by(type=image_sizes_type).one() except NoResultFound: - image_sizes = ImageSizes(image_sizes_type, 1300, 500, True, 100, 75, 30, True, 100, 500, 200, True, 100) - + if (image_sizes_type == 'speaker-image'): + image_sizes = ImageSizes(image_sizes_type, icon_size_width_height=35, icon_size_quality=80, + small_size_width_height=50, small_size_quality=80, + thumbnail_size_width_height=500, thumbnail_quality=80) + else: + image_sizes = ImageSizes(image_sizes_type, full_width=1300, + full_height=500, full_aspect=True, full_quality=80, + icon_width=75, icon_height=30, icon_aspect=True, + icon_quality=80, thumbnail_width=500, thumbnail_height=200, + thumbnail_aspect=True, thumbnail_quality=80, logo_width=500, + logo_height=200) # Get an unique identifier from uuid if not provided if unique_identifier is None: unique_identifier = get_file_name() diff --git a/docs/api/blueprint/user/users.apib b/docs/api/blueprint/user/users.apib index 67734822f6..c2c149f74c 100644 --- a/docs/api/blueprint/user/users.apib +++ b/docs/api/blueprint/user/users.apib @@ -204,7 +204,7 @@ Create a new user using an email, password and an optional name. { "email": "email@example.com", "password": "password", - "avatar_url": "http://example.com/example.png", + "avatar_url": "https://image.flaticon.com/icons/png/64/126/126486.png", "first-name": "John", "last-name": "Doe", "details": "example", @@ -213,7 +213,7 @@ Create a new user using an email, password and an optional name. "twitter-url": "http://twitter.com/twitter", "instagram-url": "http://instagram.com/instagram", "google-plus-url": "http://plus.google.com/plus.google", - "original-image-url": "https://cdn.pixabay.com/photo/2013/11/23/16/25/birds-216412_1280.jpg" + "original-image-url": "https://image.flaticon.com/icons/png/64/126/126486.png" }, "type": "user" } @@ -550,7 +550,7 @@ Authorized user should be same as user in request body or must be admin. "data": { "attributes": { "password": "password", - "avatar_url": "http://example.com/example.png", + "avatar_url": "https://image.flaticon.com/icons/png/64/126/126486.png", "first-name": "John", "last-name": "Doe", "details": "example1", @@ -559,9 +559,9 @@ Authorized user should be same as user in request body or must be admin. "twitter-url": "http://twitter.com/twitter", "instagram-url": "http://instagram.com/instagram", "google-plus-url": "http://plus.google.com/plus.google", - "thumbnail-image-url": "http://example.com/example.png", - "small-image-url": "http://example.com/example.png", - "icon-image-url": "http://example.com/example.png" + "thumbnail-image-url": "https://image.flaticon.com/icons/png/64/126/126486.png", + "small-image-url": "https://image.flaticon.com/icons/png/64/126/126486.png", + "icon-image-url": "https://image.flaticon.com/icons/png/64/126/126486.png" }, "type": "user", "id": "2"