Skip to content

Commit

Permalink
fix: Image resizing performed using requests library
Browse files Browse the repository at this point in the history
  • Loading branch information
codedsun committed Dec 6, 2019
1 parent 6d098cb commit 827477b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 13 additions & 3 deletions app/api/helpers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import urllib.parse
import urllib.request
import uuid
import requests

import PIL
from PIL import Image
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions docs/api/blueprint/user/users.apib
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Create a new user using an email, password and an optional name.
{
"email": "[email protected]",
"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",
Expand All @@ -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"
}
Expand Down Expand Up @@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit 827477b

Please sign in to comment.