node-resemble icon indicating copy to clipboard operation
node-resemble copied to clipboard

getImageDataUrl doesn't exist on the diff data object

Open jkieley opened this issue 9 years ago • 5 comments

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?

jkieley avatar Jan 14 '16 15:01 jkieley

@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));
});

jkieley avatar Feb 21 '16 15:02 jkieley

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 ??

franck34 avatar Feb 21 '16 17:02 franck34

Ha. Got it. Was using this fork : https://github.com/nikrolls/node-resemble

franck34 avatar Feb 21 '16 17:02 franck34

@jkieley this repo does not contain any "getDiffImage" occurence :)

franck34 avatar Feb 21 '16 17:02 franck34

@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
  });
});

juliend2 avatar Oct 20 '16 21:10 juliend2