Skip to content

Make percent requests that exceed 100% bound to 100% - #1319

Merged
JackLewis-digirati merged 3 commits into
developfrom
fix/largerPct
Sep 29, 2026
Merged

JackLewis-digirati merged 3 commits into
developfrom
fix/largerPct

Conversation

@JackLewis-digirati

@JackLewis-digirati JackLewis-digirati commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

What does this change?

Resolves #1117

This PR modifies how percent regions larger than 100%, request an image from cantaloupe at the upper bound of the image, rather than larger so that instead of receiving an error from cantaloupe for requesting an image larger than the size, the image will be returned

@JackLewis-digirati
JackLewis-digirati requested a review from a team as a code owner September 28, 2026 11:39
@JackLewis-digirati

Copy link
Copy Markdown
Collaborator Author

Fixes #1117

Problem

When a request's {region} extends beyond the image's dimensions (e.g. pct:0,0,101,101, or 3471,5079,512,512 on a 3771x5279 image) the IIIF spec says the service should crop at the image's edge:

If the request specifies a region which extends beyond the dimensions of the full image as reported in the image information document, then the service SHOULD return an image cropped at the image’s edge, rather than adding empty space.

iiif-net's RegionParameter.GetExtractedRegionSize() already does this cropping when calculating the extracted region size, so Orchestrator's size/maxWidth calculations were correct. However the original region was still proxied to the image server unaltered, which Cantaloupe rejects (e.g. pct: > 100 results in a 500 Width must be <= 1).

How this fixes it

Orchestrator now rewrites the region before proxying, the same way it already rewrites the size parameter:

  • IIIFX.ConfineToImageBounds(RegionParameter, Size) - returns a copy of the region with w/h reduced so that x + w and y + h don't exceed the image bounds. The bound is 100 for pct: regions and the image's width/height for pixel regions. full and square are returned unaltered.
    • pct:0,0,101,101 ➡️ pct:0,0,100,100
    • pct:50,50,60,60 ➡️ pct:50,50,50,50
    • 6632,3682,512,512 on a 6932x3982 image ➡️ 6632,3682,300,300
  • ImageProxyPathHandler - calls ConfineToImageBounds after GetExtractedRegionSize (so requests where x/y are outside the image still fail validation first) and returns the result on the new ProxyImageRequest.ProxyRegionParameter property.
  • ImageRequestHandler - sets IIIFImageRequest.Region from ProxyRegionParameter alongside the existing Size rewrite, so the image server only ever receives an in-bounds region.

IsFullOrEquivalent is now evaluated against the confined region, so a region like pct:0,0,101,101 or 0,0,7000,4000 (on a 6932x3982 image) is treated as a full-region request and is a candidate for being served by thumbs / special-server, same as full or pct:0,0,100,100.

Unchanged behaviour

Regions where x or y are outside the image (e.g. pct:101,0,10,10) still return 400 Region is outside image bounds, and zero width/height regions still return 400.

Tests

  • Unit tests for ConfineToImageBounds covering pixel and percent regions, full and square.
  • ImageProxyPathHandlerTests - V2 and V3 (strict + lax) tests asserting the confined region + resulting size, and additional "represents full region" cases for oversized regions.
  • ImageHandlingTests integration tests asserting the region in the URI proxied to the image server is cropped for both pixel and pct: regions.

@JackLewis-digirati JackLewis-digirati changed the title Mae percent requests that exceed 100% bound to 100% Make percent requests that exceed 100% bound to 100% Sep 28, 2026
Comment thread src/protagonist/Orchestrator.Tests/Integration/ImageHandlingTests.cs Outdated
@JackLewis-digirati
JackLewis-digirati merged commit 899b1b6 into develop Sep 29, 2026
8 checks passed
@JackLewis-digirati
JackLewis-digirati deleted the fix/largerPct branch September 29, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image region requests including a pct: size parameter larger than 100% result in 500

2 participants