diff --git a/docs/changelog.md b/docs/changelog.md index 96e525c7..2e709b2e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,10 @@ Requires libvips v8.3.3 [#561](https://github.com/lovell/sharp/issues/561) [@abagshaw](https://github.com/abagshaw) +* Correct calculation of y-axis placement when overlaying image at a fixed point. + [#566](https://github.com/lovell/sharp/issues/566) + [@Nateowami](https://github.com/Nateowami) + #### v0.16.0 - 18th August 2016 * Add pre-compiled libvips for OS X, ARMv7 and ARMv8. diff --git a/src/common.cc b/src/common.cc index 1babef46..4ed3e4ca 100644 --- a/src/common.cc +++ b/src/common.cc @@ -391,7 +391,7 @@ namespace sharp { if(y >= 0 && y < (inHeight - outHeight)) { top = y; - } else if(x >= (inHeight - outHeight)) { + } else if(y >= (inHeight - outHeight)) { top = inHeight - outHeight; } diff --git a/test/fixtures/expected/overlay-bottom-edges-meet.jpg b/test/fixtures/expected/overlay-bottom-edges-meet.jpg new file mode 100644 index 00000000..edc7c249 Binary files /dev/null and b/test/fixtures/expected/overlay-bottom-edges-meet.jpg differ diff --git a/test/unit/overlay.js b/test/unit/overlay.js index f67697ff..40c37161 100644 --- a/test/unit/overlay.js +++ b/test/unit/overlay.js @@ -437,7 +437,27 @@ describe('Overlays', function() { assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - + }); + + it('Overlay 100x100 with 50x50 so bottom edges meet', function(done) { + sharp(fixtures.inputJpg) + .resize(50, 50) + .toBuffer(function(err, overlay) { + if (err) throw err; + sharp(fixtures.inputJpgWithLandscapeExif1) + .resize(100, 100) + .overlayWith(overlay, { + top: 50, + left: 40 + }) + .toBuffer(function(err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(100, info.width); + assert.strictEqual(100, info.height); + fixtures.assertSimilar(fixtures.expected('overlay-bottom-edges-meet.jpg'), data, done); + }); + }); }); });