From ac2007dd9baa6933cc5656dab454cfb4631353aa Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 2 Oct 2016 21:28:31 -0700 Subject: [PATCH] resize_avatar: Add a size option. --- zerver/lib/upload.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zerver/lib/upload.py b/zerver/lib/upload.py index 457a49d984..bc4f9f8b7c 100644 --- a/zerver/lib/upload.py +++ b/zerver/lib/upload.py @@ -32,6 +32,8 @@ import io import random import logging +DEFAULT_AVATAR_SIZE = 100 + # Performance Note: # # 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): pass -def resize_avatar(image_data): - # type: (binary_type) -> binary_type - AVATAR_SIZE = 100 +def resize_avatar(image_data, size=DEFAULT_AVATAR_SIZE): + # type: (binary_type, int) -> binary_type try: 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: raise BadImageError("Could not decode avatar image; did you upload an image file?") out = io.BytesIO()