Skip to content

Commit

Permalink
Ensure resize fit=inside respects 90/270 rotate #3756
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Aug 14, 2023
1 parent 3d01775 commit 5c19f6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Requires libvips v8.14.3
[#3755](https://github.com/lovell/sharp/pull/3755)
[@kleisauke](https://github.com/kleisauke)

* Ensure resize with a `fit` of `inside` respects 90/270 degree rotation.
[#3756](https://github.com/lovell/sharp/issues/3756)

* TypeScript: Ensure `minSize` property of `WebpOptions` is boolean.
[#3758](https://github.com/lovell/sharp/pull/3758)
[@sho-xizz](https://github.com/sho-xizz)
Expand Down
3 changes: 3 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ namespace sharp {
if (swap && canvas != Canvas::IGNORE_ASPECT) {
// Swap input width and height when requested.
std::swap(width, height);
if (canvas == Canvas::MAX) {
std::swap(targetWidth, targetHeight);
}
}

double hshrink = 1.0;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,28 @@ describe('Rotation', function () {
.timeout({ seconds: 5 })
.toBuffer()
);

it('Rotate 90 then resize with inside fit', async () => {
const data = await sharp({ create: { width: 16, height: 8, channels: 3, background: 'red' } })
.rotate(90)
.resize({ width: 6, fit: 'inside' })
.png({ compressionLevel: 0 })
.toBuffer();

const { width, height } = await sharp(data).metadata();
assert.strictEqual(width, 6);
assert.strictEqual(height, 12);
});

it('Resize with inside fit then rotate 90', async () => {
const data = await sharp({ create: { width: 16, height: 8, channels: 3, background: 'red' } })
.resize({ width: 6, fit: 'inside' })
.rotate(90)
.png({ compressionLevel: 0 })
.toBuffer();

const { width, height } = await sharp(data).metadata();
assert.strictEqual(width, 3);
assert.strictEqual(height, 6);
});
});

0 comments on commit 5c19f6d

Please sign in to comment.