Skip to content

Commit

Permalink
Ensure composite can tile with outside resize #3227
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Jun 8, 2022
1 parent 4d82331 commit a757185
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ceil(static_cast<double>(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<int>(ceil(static_cast<double>(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) {
Expand Down
27 changes: 27 additions & 0 deletions test/unit/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit a757185

Please sign in to comment.