From 7b332cc3fc469c1f049b5f5202afb938a29fcc5a Mon Sep 17 00:00:00 2001 From: Toranova Date: Tue, 19 Jan 2021 23:54:30 +0800 Subject: [PATCH] remove print statement from avatar crop, add switch for uuid filename generation --- flask_avatars/__init__.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flask_avatars/__init__.py b/flask_avatars/__init__.py index acd2f73..835efc4 100644 --- a/flask_avatars/__init__.py +++ b/flask_avatars/__init__.py @@ -296,7 +296,7 @@ def save_avatar(self, image): image.save(os.path.join(path, filename)) return filename - def crop_avatar(self, filename, x, y, w, h): + def crop_avatar(self, filename, x, y, w, h, uuid_filename = True): """Crop avatar with given size, return a list of file name: [filename_s, filename_m, filename_l]. :param filename: The raw image's filename. @@ -317,8 +317,6 @@ def crop_avatar(self, filename, x, y, w, h): else: path = os.path.join(current_app.config['AVATARS_SAVE_PATH'], filename) - print(path) - raw_img = Image.open(path) base_width = current_app.config['AVATARS_CROP_BASE_WIDTH'] @@ -328,7 +326,8 @@ def crop_avatar(self, filename, x, y, w, h): cropped_img = raw_img.crop((x, y, x + w, y + h)) - filename = uuid4().hex + if uuid_filename: + filename = uuid4().hex avatar_s = self.resize_avatar(cropped_img, base_width=sizes[0]) avatar_m = self.resize_avatar(cropped_img, base_width=sizes[1])