Ensure resize fit=inside respects 90/270 rotate #3756

This commit is contained in:
Lovell Fuller 2023-08-14 13:45:23 +01:00
parent 3d01775972
commit 5c19f6dd9b
3 changed files with 30 additions and 0 deletions

View File

@ -14,6 +14,9 @@ Requires libvips v8.14.3
[#3755](https://github.com/lovell/sharp/pull/3755) [#3755](https://github.com/lovell/sharp/pull/3755)
[@kleisauke](https://github.com/kleisauke) [@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. * TypeScript: Ensure `minSize` property of `WebpOptions` is boolean.
[#3758](https://github.com/lovell/sharp/pull/3758) [#3758](https://github.com/lovell/sharp/pull/3758)
[@sho-xizz](https://github.com/sho-xizz) [@sho-xizz](https://github.com/sho-xizz)

View File

@ -968,6 +968,9 @@ namespace sharp {
if (swap && canvas != Canvas::IGNORE_ASPECT) { if (swap && canvas != Canvas::IGNORE_ASPECT) {
// Swap input width and height when requested. // Swap input width and height when requested.
std::swap(width, height); std::swap(width, height);
if (canvas == Canvas::MAX) {
std::swap(targetWidth, targetHeight);
}
} }
double hshrink = 1.0; double hshrink = 1.0;

View File

@ -489,4 +489,28 @@ describe('Rotation', function () {
.timeout({ seconds: 5 }) .timeout({ seconds: 5 })
.toBuffer() .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);
});
}); });