From 300d43352a2845aad289b254bfbdc7cd6a37e2d7 Mon Sep 17 00:00:00 2001 From: Jon Wallsten Date: Thu, 24 Nov 2016 14:41:22 +0100 Subject: [PATCH 1/3] Fixed issue where scaleToSameSize is not working when using node-canvas. Can't set image dimensions. --- resemble.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/resemble.js b/resemble.js index 67f6eda..4103590 100644 --- a/resemble.js +++ b/resemble.js @@ -174,16 +174,16 @@ URL: https://github.com/Huddle/Resemble.js var hiddenCanvas = document.createElement('canvas'); var imageData; - if( scaleToSameSize && images.length == 1 ){ - hiddenImage.width = images[0].width; - hiddenImage.height = images[0].height; - } - var width = hiddenImage.width; - var height = hiddenImage.height; + var height = hiddenImage.height; + + if( scaleToSameSize && images.length == 1 ){ + width = images[0].width; + height = images[0].height; + } - hiddenCanvas.width = width; - hiddenCanvas.height = height; + hiddenCanvas.width = width; + hiddenCanvas.height = height; hiddenCanvas.getContext('2d').drawImage(hiddenImage, 0, 0, width, height); imageData = hiddenCanvas.getContext('2d').getImageData(0, 0, width, height); From 1ef9a2be4d8fd35b1fac1472decb2bdfedc33686 Mon Sep 17 00:00:00 2001 From: Jon Wallsten Date: Thu, 24 Nov 2016 14:47:17 +0100 Subject: [PATCH 2/3] What sane person uses tabs? --- resemble.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resemble.js b/resemble.js index 4103590..5514235 100644 --- a/resemble.js +++ b/resemble.js @@ -175,15 +175,15 @@ URL: https://github.com/Huddle/Resemble.js var imageData; var width = hiddenImage.width; - var height = hiddenImage.height; + var height = hiddenImage.height; - if( scaleToSameSize && images.length == 1 ){ - width = images[0].width; - height = images[0].height; - } + if( scaleToSameSize && images.length == 1 ){ + width = images[0].width; + height = images[0].height; + } - hiddenCanvas.width = width; - hiddenCanvas.height = height; + hiddenCanvas.width = width; + hiddenCanvas.height = height; hiddenCanvas.getContext('2d').drawImage(hiddenImage, 0, 0, width, height); imageData = hiddenCanvas.getContext('2d').getImageData(0, 0, width, height); From b2f491d1df6db7d4615cd8361c0cd14ff21bbf9c Mon Sep 17 00:00:00 2001 From: "james.cryer" Date: Tue, 6 Dec 2016 11:51:01 +0000 Subject: [PATCH 3/3] minor tweaks --- resemble.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/resemble.js b/resemble.js index 5514235..754458c 100644 --- a/resemble.js +++ b/resemble.js @@ -174,16 +174,18 @@ URL: https://github.com/Huddle/Resemble.js var hiddenCanvas = document.createElement('canvas'); var imageData; + // don't assign to hiddenImage, see https://github.com/Huddle/Resemble.js/pull/87/commits/300d43352a2845aad289b254bfbdc7cd6a37e2d7 var width = hiddenImage.width; var height = hiddenImage.height; if( scaleToSameSize && images.length == 1 ){ - width = images[0].width; - height = images[0].height; + width = images[0].width; + height = images[0].height; } hiddenCanvas.width = width; hiddenCanvas.height = height; + hiddenCanvas.getContext('2d').drawImage(hiddenImage, 0, 0, width, height); imageData = hiddenCanvas.getContext('2d').getImageData(0, 0, width, height); @@ -200,8 +202,11 @@ URL: https://github.com/Huddle/Resemble.js } else if (typeof fileData.data !== 'undefined' && typeof fileData.width === 'number' && typeof fileData.height === 'number') { + images.push(fileData); + callback(fileData, fileData.width, fileData.height); + } else { fileReader = new FileReader(); fileReader.onload = function (event) { @@ -231,10 +236,6 @@ URL: https://github.com/Huddle/Resemble.js } } - function isNumber(n) { - return !isNaN(parseFloat(n)); - } - function isPixelBrightnessSimilar(d1, d2){ var alpha = isColorSimilar(d1.a, d2.a, 'alpha'); var brightness = isColorSimilar(d1.brightness, d2.brightness, 'minBrightness');