Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function rotate (angle, options) {
this.options.rotationAngle = 0;
}
if (is.integer(angle) && !(angle % 90)) {
this.options.angle = angle;
this.options.angle = angle % 360;
} else if (is.number(angle)) {
this.options.rotationAngle = angle;
if (is.object(options) && options.background) {
Expand Down
2 changes: 1 addition & 1 deletion lib/output.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ function tile (options) {
// Angle of rotation,
if (is.defined(options.angle)) {
if (is.integer(options.angle) && !(options.angle % 90)) {
this.options.tileAngle = options.angle;
this.options.tileAngle = options.angle % 360;
} else {
throw is.invalidParameterError('angle', 'positive/negative multiple of 90', options.angle);
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ suite('Rotation', () => {
});
});

// A 90-multiple angle larger than the 32-bit integer range is normalised
// modulo 360 rather than silently truncated when read natively
[90 * 47721859, 90 * 47721861, -90 * 47721859].forEach((angle) => {
test(`Rotate by a 90-multiple angle beyond 32-bit range (${angle}deg)`, async (t) => {
t.plan(2);
const { info } = await bufferWithInfo(sharp(fixtures.inputJpg320x240).rotate(angle));
t.assert.strictEqual(240, info.width);
t.assert.strictEqual(320, info.height);
});
});

[-3750, -510, -150, 30, 390, 3630].forEach((angle) => {
test(`Rotate by any 30-multiple angle (${angle}deg)`, async (t) => {
t.plan(2);
Expand Down
19 changes: 19 additions & 0 deletions test/unit/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,25 @@ suite('Tile', () => {
t.assert.strictEqual(true, metadata.height === 170);
});

test('Deep Zoom layout with angle beyond 32-bit integer range', async (t) => {
const directory = fixtures.path('output.512_largeangle.dzi_files');
await fs.rm(directory, { recursive: true, force: true });
// 2147483970 is a multiple of 90 equal to 90 modulo 360 but larger than
// the signed 32-bit range, so it must rotate as 90 rather than truncate
const info = await sharp(fixtures.inputJpg)
.tile({
size: 512,
angle: 2147483970
})
.toFile(fixtures.path('output.512_largeangle.dzi'));
t.plan(3);
t.assert.strictEqual('dz', info.format);
const tile = path.join(directory, '10', '0_1.jpeg');
const metadata = await sharp(tile).metadata();
t.assert.strictEqual(true, metadata.width === 512);
t.assert.strictEqual(true, metadata.height === 170);
});

test('Deep Zoom layout with depth of one', async (t) => {
const directory = fixtures.path('output.512_depth_one.dzi_files');
await fs.rm(directory, { recursive: true, force: true });
Expand Down
Loading