Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resize: added upscaling params for h & w #100

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions flask_iiif/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down