From 486f5d1ca6a1f50561714db87e30ce72be428976 Mon Sep 17 00:00:00 2001 From: Fatimah Zulfiqar Date: Wed, 21 Aug 2024 14:51:28 +0200 Subject: [PATCH] resize: added upscaling params for h & w --- flask_iiif/api.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/flask_iiif/api.py b/flask_iiif/api.py index d702865..243ed01 100644 --- a/flask_iiif/api.py +++ b/flask_iiif/api.py @@ -152,9 +152,13 @@ def resize(self, dimensions, resample=None): width = max(1, int(real_width * percent)) height = max(1, int(real_height * percent)) - # Check if it is `,h` - elif dimensions.startswith(","): - height = int(dimensions[1:]) + # Check if it is `,h` or `^,h` + elif dimensions.startswith(",") or dimensions.startswith("^,"): + if dimensions.startswith(","): # Handle `,h` + height = int(dimensions[1:]) + else: # Handle `^,h` + height = int(dimensions[2:]) + # find the ratio ratio = self.reduce_by(height, real_height) # calculate width (minimum 1) @@ -172,9 +176,17 @@ def resize(self, dimensions, resample=None): width = max(1, int(real_width * ratio)) height = max(1, int(real_height * ratio)) - # Check if it is `w,` - elif dimensions.endswith(","): - width = int(dimensions[:-1]) + # Check if it is `w,` or `^w,` + elif dimensions.endswith(",") or ( + (dimensions.startswith("^") and dimensions.endswith(",")) + ): + if dimensions.endswith(",") and not dimensions.startswith( + "^" + ): # Handle `w,` + width = int(dimensions[:-1]) + else: # Handle `^w,` + width = int(dimensions[1:-1]) + # find the ratio ratio = self.reduce_by(width, real_width) # calculate the height