node-resemble
node-resemble copied to clipboard
getImageDataUrl doesn't exist on the diff data object
getImageDataUrl doesn't exist on the diff data object. I get { isSameDimensions: false, dimensionDifference: { width: 0, height: -154 }, misMatchPercentage: '22.48', analysisTime: 346, getDiffImage: [Function] } }
It looks like getDiffImage, returns a node stream... But I'm unable to write it to a file... could you give an example?
@franck34 After digging through the source code, I was able to come up with this solution to write the image to a file:
var png = data.getDiffImage();
var imageName = "out.png";
png.pack().pipe(fs.createWriteStream(imageName));
png.on('parsed', function() {
return png.pack().pipe(fs.createWriteStream(imageName));
});
Same here, but i had to clone another branch because getDiffImage does not exist on master branch.
I did it few hours ago. But curiously branches vanished from github. Or perhaps i'm really tired ??
Ha. Got it. Was using this fork : https://github.com/nikrolls/node-resemble
@jkieley this repo does not contain any "getDiffImage" occurence :)
@jkieley here is what I did and it seems to work:
var fs = require('fs');
var resemble = require('node-resemble');
var img1 = fs.readFileSync('before.png');
var img2 = fs.readFileSync('after.png');
resemble(img1).compareTo(img2).onComplete(function(data){
var png = data.getImageDataUrl();
var base64Data = png.replace(/^data:image\/png;base64,/, "");
fs.writeFile("out.png", base64Data, 'base64', function(err) {
console.log(err); // if any
});
});