lksv / node-resemble.js

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

Please update Readme #4

Closed sfishel18 closed 9 years ago

sfishel18 commented 9 years ago

Great library, it was exactly what I needed for a recent project! But I ran into a few pain points due to the fact that that parts of the Readme don't seem to have been updated since forking from Resemble.js. Specifically, what are the best practices for capturing a diff image and saving it off? This is how I'm currently doing it, but I'm not sure if it's the best way:

resemble(image1).compareTo(image2).onComplete(function(data) {
    data.getDiffImage().pack().pipe(
        fs.createWriteStream(diffImagePath)
    );
});

Thanks!

lksv commented 9 years ago

Thanks for feedback. It is good point.

Just for now, here is a simple snippet, how it could be used in cucumber step definitin (with using protractor):

 this.Then(/^Screenshot should match image "(.*)"$/, function (image, callback) {
   browser.takeScreenshot().then(function(pngString) {
     var screenshot = new Buffer(pngString, 'base64');

     resemble(image)
       .compareTo(screenshot)
       .onComplete(function(data){

         if (Number(data.misMatchPercentage) <= 0.01) {
           callback();
         } else {
           data.getDiffImage().pack().pipe(fs.createWriteStream(image + 'diff.png'));
           callback.fail(new Error("Screenshot '" + image+  "' differ " + data.misMatchPercentage + "%"));
         }
       });
   });
 })  

Is it what you are seeking for?

sfishel18 commented 9 years ago

Yes, that's very helpful. Thank you!

SimitTomar commented 8 years ago

Hi There,

Thanks for this library.

I tried to follow the above example but getting an empty diff image, tried the following code:

var imgData1 = 'C:\\Users\\Image1.png';
var imgData2 = 'C:\\Users\\Image2.png';

var diffImage = 'C:\\Users\\';

resemble(imgData1).compareTo(imgData2).ignoreNothing().onComplete(function (data) {

    data.getDiffImage().pack().pipe(fs.createWriteStream( diffImage + 'diff.png'));
    console.log(data);
})

Log shows that the 2 images are different:

{ isSameDimensions: true,
  dimensionDifference: { width: 0, height: 0 },
  misMatchPercentage: '0.73',
  analysisTime: 143,
  getDiffImage: [Function] }

Not sure what am I missing here, any help would be much appreciated