mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
resize_avatar: Add a size option.
This commit is contained in:
@@ -32,6 +32,8 @@ import io
|
|||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
DEFAULT_AVATAR_SIZE = 100
|
||||||
|
|
||||||
# Performance Note:
|
# Performance Note:
|
||||||
#
|
#
|
||||||
# For writing files to S3, the file could either be stored in RAM
|
# For writing files to S3, the file could either be stored in RAM
|
||||||
@@ -80,12 +82,11 @@ def random_name(bytes=60):
|
|||||||
class BadImageError(JsonableError):
|
class BadImageError(JsonableError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def resize_avatar(image_data):
|
def resize_avatar(image_data, size=DEFAULT_AVATAR_SIZE):
|
||||||
# type: (binary_type) -> binary_type
|
# type: (binary_type, int) -> binary_type
|
||||||
AVATAR_SIZE = 100
|
|
||||||
try:
|
try:
|
||||||
im = Image.open(io.BytesIO(image_data))
|
im = Image.open(io.BytesIO(image_data))
|
||||||
im = ImageOps.fit(im, (AVATAR_SIZE, AVATAR_SIZE), Image.ANTIALIAS)
|
im = ImageOps.fit(im, (size, size), Image.ANTIALIAS)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise BadImageError("Could not decode avatar image; did you upload an image file?")
|
raise BadImageError("Could not decode avatar image; did you upload an image file?")
|
||||||
out = io.BytesIO()
|
out = io.BytesIO()
|
||||||
|
|||||||
Reference in New Issue
Block a user