Skip to content
Closed
Show file tree
Hide file tree
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
17 changes: 2 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/calculator/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Calculator extends Base {
}
super.size(v);
const { region, size, upscale } = this._parsedInfo;
if (!upscale) {
if (!upscale && size.fit !== 'inside') {
if (size.width > region.width || size.height > region.height) {
throw new IIIFError('Requested size requires upscaling', {
statusCode: 400
Expand Down
34 changes: 34 additions & 0 deletions tests/v3/calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { Calculator } from '../../src/calculator/v3';
import { IIIFError } from '../../src/error';
import values from '../fixtures/iiif-values';
const { v3: { qualities, formats, regions, sizes, rotations } } = values as any;

Check warning on line 9 in tests/v3/calculator.test.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

let subject;

Expand Down Expand Up @@ -154,6 +154,40 @@
subject.region('pct:50,50,25,25').size('^512,384').rotation('45').quality('default').format('jpg', 600);
assert.deepEqual(subject.info(), expected);
});

it('allows best-fit sizing larger than source without upscaling error', () => {
subject = new Calculator({ width: 1024, height: 768 });

// !9000,9000 should not throw even though dimensions exceed source
assert.doesNotThrow(() => {
subject
.region('full')
.size('!9000,9000')
.rotation('0')
.quality('default')
.format('jpg');
}, IIIFError);

const result = subject.info();
assert.equal(result.size.fit, 'inside');
assert.equal(result.size.width, 9000);
assert.equal(result.size.height, 9000);
assert.equal(result.upscale, false);
});

it('throws upscaling error for exact size larger than source', () => {
subject = new Calculator({ width: 1024, height: 768 });

// 9000,9000 without ! should throw upscaling error
assert.throws(() => {
subject
.region('full')
.size('9000,9000')
.rotation('0')
.quality('default')
.format('jpg');
}, IIIFError);
});
});

describe('density', () => {
Expand Down
Loading