lksv / node-resemble.js

LOOKING FOR MAINTAINER - Image analysis and comparison
MIT License
99 stars 37 forks source link

How do I get the diff image ? #19

Closed mandeepm91 closed 8 years ago

mandeepm91 commented 8 years ago

I am using the node.js library and trying to get the diff image after comparing two images. I am using the following code snippet for this but unable to open the image since it appears to be corrupted. What is the right way to do this ?

var diff = resemble(fileData).compareTo(fileData2).onComplete(function(data){
  console.log(data);
  var diffData = data.getDiffImage().data
  console.log(diffData);
  fs.writeFileSync(path.join(process.env.HOME,"Desktop", "diff.png"), diffData.toString())
})
mandeepm91 commented 8 years ago

Got it working. Figured I had to use the pack method to create a stream out of data.

var diff = resemble(fileData).compareTo(fileData2).onComplete(function(data){
  console.log(data);
  var diffDataStream = data.getDiffImage().pack()
  var writeStream = fs.createWriteStream(path.join(process.env.HOME,"Desktop", "diff.png"))
  diffDataStream.pipe(writeStream)
});
mandeepm91 commented 8 years ago

Need to call the pack method of the function's response to covert it to a readable stream