From a9a393b18b9f7653e569038334e86c325e6cc343 Mon Sep 17 00:00:00 2001 From: fleg Date: Wed, 15 Feb 2017 19:54:47 +0300 Subject: [PATCH] Fix crop with downsamplingRatio --- js/load-image.js | 2 ++ test/test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/js/load-image.js b/js/load-image.js index e7fe73c..848c9d8 100644 --- a/js/load-image.js +++ b/js/load-image.js @@ -285,6 +285,8 @@ canvas.width, canvas.height ) + sourceX = 0 + sourceY = 0 sourceWidth = canvas.width sourceHeight = canvas.height img = document.createElement('canvas') diff --git a/test/test.js b/test/test.js index bd260a1..862b753 100644 --- a/test/test.js +++ b/test/test.js @@ -336,6 +336,23 @@ done() }, {sourceWidth: 40, sourceHeight: 40, crop: true, pixelRatio: 2})).to.be.ok }) + + it('Crop using maxWidth/maxHeight with the given downsamplingRatio', function (done) { + expect(loadImage(blobGIF, function (img) { + expect(img.width).to.equal(10) + expect(img.height).to.equal(10) + + var data = img.getContext('2d').getImageData(0, 0, 10, 10).data + for (var i = 0; i < data.length / 4; i += 4) { + expect(data[i]).to.equal(0) + expect(data[i + 1]).to.equal(0) + expect(data[i + 2]).to.equal(0) + expect(data[i + 3]).to.equal(255) + } + + done() + }, {maxWidth: 10, maxHeight: 10, crop: true, downsamplingRatio: 0.5})).to.be.ok + }) }) describe('Orientation', function () {