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