Skip to content

Commit

Permalink
resize: added upscaling params for h & w
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 committed Aug 21, 2024
1 parent 8d65dbc commit a36b59a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions flask_iiif/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -172,9 +176,13 @@ 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
Expand Down

0 comments on commit a36b59a

Please sign in to comment.