From 34829e0733a4acaaef78281cd22a609fde61f405 Mon Sep 17 00:00:00 2001 From: jacquesfize Date: Thu, 19 Dec 2024 10:16:53 +0100 Subject: [PATCH] fix(thumbnail, generation): now can use the thumbnail generation with only the width GET arg --- apptax/taxonomie/filemanager.py | 6 +++++- apptax/taxonomie/routestmedias.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apptax/taxonomie/filemanager.py b/apptax/taxonomie/filemanager.py index a04e7c8a..90096887 100644 --- a/apptax/taxonomie/filemanager.py +++ b/apptax/taxonomie/filemanager.py @@ -94,10 +94,14 @@ def create_thumb(self, media, size, force=False, regenerate=False): # Get Image try: - img = self._get_image_object(media) + img: Image = self._get_image_object(media) except TaxhubError as e: return None + # If width only was given in the parameter (height <=> size[1] < 0) + if size[1] < 0: + size[1] = img.width / size[0] * img.height + # Création du thumbnail resizeImg = resize_thumbnail(img, (size[0], size[1], force)) # Sauvegarde de l'image diff --git a/apptax/taxonomie/routestmedias.py b/apptax/taxonomie/routestmedias.py index f8ae7bfb..a487d3f6 100644 --- a/apptax/taxonomie/routestmedias.py +++ b/apptax/taxonomie/routestmedias.py @@ -10,6 +10,7 @@ from .filemanager import FILEMANAGER +DEFAULT_THUMBNAIL_SIZE = (300, 400) adresses = Blueprint("t_media", __name__) logger = logging.getLogger() @@ -84,9 +85,17 @@ def getThumbnail_tmedias(id_media): ) params = request.args - size = (300, 400) - if ("h" in params) or ("w" in params): - size = (int(params.get("h", -1)), int(params.get("w", -1))) + + size = DEFAULT_THUMBNAIL_SIZE + + height_params: str = params.get("h", "-1") + width_params: str = params.get("w", "-1") + + if width_params and width_params.isdigit(): + size = (int(width_params), size[1]) + + if height_params and height_params.isdigit(): + size = (size[0], int(height_params)) force = False if ("force" in params) and (params.get("force") == "true"):