Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getImageDataUrl doesn't exist on the diff data object #8

Open
jkieley opened this issue Jan 14, 2016 · 5 comments
Open

getImageDataUrl doesn't exist on the diff data object #8

jkieley opened this issue Jan 14, 2016 · 5 comments

Comments

@jkieley
Copy link

jkieley commented Jan 14, 2016

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
Copy link
Author

jkieley commented Feb 21, 2016

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

@franck34
Copy link

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
Copy link

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

@franck34
Copy link

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

@juliend2
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants