From 48babaaf5fe5806bae064532c8ca67332f7e5905 Mon Sep 17 00:00:00 2001 From: Fatimah Zulfiqar Date: Mon, 26 Aug 2024 13:06:30 +0200 Subject: [PATCH] resize: added upscaling params for h & w --- flask_iiif/api.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/flask_iiif/api.py b/flask_iiif/api.py index d702865..626321b 100644 --- a/flask_iiif/api.py +++ b/flask_iiif/api.py @@ -152,9 +152,14 @@ 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`, + # the '^' case is handled the same way as just height being present + elif 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 +177,18 @@ 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,` + # the '^' case is handled the same way as just width being present + 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