From a75718565cf3c2ad24a5a3bfe50559b658e9785f Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 8 Jun 2022 12:39:00 +0100 Subject: [PATCH] Ensure composite can tile with outside resize #3227 --- docs/changelog.md | 5 +++++ src/pipeline.cc | 4 ++-- test/unit/composite.js | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 717990fe0..ab38fca3e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ Requires libvips v8.12.2 +### v0.30.7 - TBD + +* Ensure tiled composition always works with outside resizing. + [#3227](https://github.com/lovell/sharp/issues/3227) + ### v0.30.6 - 30th May 2022 * Allow values for `limitInputPixels` larger than 32-bit. diff --git a/src/pipeline.cc b/src/pipeline.cc index 437c4a1e9..2744d3d26 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -607,14 +607,14 @@ class PipelineWorker : public Napi::AsyncWorker { int across = 0; int down = 0; // Use gravity in overlay - if (compositeImage.width() <= baton->width) { + if (compositeImage.width() <= image.width()) { across = static_cast(ceil(static_cast(image.width()) / compositeImage.width())); // Ensure odd number of tiles across when gravity is centre, north or south if (composite->gravity == 0 || composite->gravity == 1 || composite->gravity == 3) { across |= 1; } } - if (compositeImage.height() <= baton->height) { + if (compositeImage.height() <= image.height()) { down = static_cast(ceil(static_cast(image.height()) / compositeImage.height())); // Ensure odd number of tiles down when gravity is centre, east or west if (composite->gravity == 0 || composite->gravity == 2 || composite->gravity == 4) { diff --git a/test/unit/composite.js b/test/unit/composite.js index 773a6ffb5..56927ccfb 100644 --- a/test/unit/composite.js +++ b/test/unit/composite.js @@ -420,4 +420,31 @@ describe('composite', () => { assert.deepStrictEqual(red, { r, g, b }); }); + + it('Ensure tiled composition works with resized fit=outside', async () => { + const { info } = await sharp({ + create: { + width: 41, height: 41, channels: 3, background: 'red' + } + }) + .resize({ + width: 10, + height: 40, + fit: 'outside' + }) + .composite([ + { + input: { + create: { + width: 16, height: 16, channels: 3, background: 'green' + } + }, + tile: true + } + ]) + .toBuffer({ resolveWithObject: true }); + + assert.strictEqual(info.width, 40); + assert.strictEqual(info.height, 40); + }); });