Skip to content

Commit 11909eb

Browse files
committed
Fix v3 best-fit sizing incorrectly requiring upscaling check
1 parent a6e6a2a commit 11909eb

3 files changed

Lines changed: 37 additions & 16 deletions

File tree

‎package-lock.json‎

Lines changed: 2 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/calculator/v3.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Calculator extends Base {
3131
}
3232
super.size(v);
3333
const { region, size, upscale } = this._parsedInfo;
34-
if (!upscale) {
34+
if (!upscale && size.fit !== 'inside') {
3535
if (size.width > region.width || size.height > region.height) {
3636
throw new IIIFError('Requested size requires upscaling', {
3737
statusCode: 400

‎tests/v3/calculator.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,40 @@ describe('Calculator', () => {
154154
subject.region('pct:50,50,25,25').size('^512,384').rotation('45').quality('default').format('jpg', 600);
155155
assert.deepEqual(subject.info(), expected);
156156
});
157+
158+
it('allows best-fit sizing larger than source without upscaling error', () => {
159+
subject = new Calculator({ width: 1024, height: 768 });
160+
161+
// !9000,9000 should not throw even though dimensions exceed source
162+
assert.doesNotThrow(() => {
163+
subject
164+
.region('full')
165+
.size('!9000,9000')
166+
.rotation('0')
167+
.quality('default')
168+
.format('jpg');
169+
}, IIIFError);
170+
171+
const result = subject.info();
172+
assert.equal(result.size.fit, 'inside');
173+
assert.equal(result.size.width, 9000);
174+
assert.equal(result.size.height, 9000);
175+
assert.equal(result.upscale, false);
176+
});
177+
178+
it('throws upscaling error for exact size larger than source', () => {
179+
subject = new Calculator({ width: 1024, height: 768 });
180+
181+
// 9000,9000 without ! should throw upscaling error
182+
assert.throws(() => {
183+
subject
184+
.region('full')
185+
.size('9000,9000')
186+
.rotation('0')
187+
.quality('default')
188+
.format('jpg');
189+
}, IIIFError);
190+
});
157191
});
158192

159193
describe('density', () => {

0 commit comments

Comments
 (0)