yahoo / blink-diff

A lightweight image comparison tool.
http://yahoo.github.io/blink-diff/
MIT License
1.21k stars 90 forks source link

Different results from command-line vs JS Object usage #16

Closed a-nwhitmont closed 9 years ago

a-nwhitmont commented 9 years ago

During testing of blink-diff I have experienced different results from the command-line usage vs. the Javascript Object usage.

Images used for this test:

people.png people

people2.png people2

Command-line Usage

Command-line script: ./node_modules/blink-diff/bin/blink-diff --output blinkdiff-people.png people.png people2.png

Command-line result:

bash-3.2$ ./blinkcli.sh
Blink-Diff 1.0.7
Copyright (C) 2014 Yahoo! Inc.
Images are visibly different
16297 pixels are different
Wrote differences to blinkdiff-people.png
Time: 197ms
Differences: 16297 (6.52%)
FAIL

Output file: blinkdiff-people.png - (Works as expected) blinkdiff-people

Javascript Object Usage

blink.js

#!/usr/bin/env node

BlinkDiff = require('blink-diff')

var diff = new BlinkDiff({
    imageAPath: 'people.png',
    imageBPath: 'people2.png',

    imageOutputPath: 'blink-diff-people.png',

    verbose: true
});

diff.run(function (error) {
    console.log(error ? 'Failed' + error : 'Passed');
});

Run the script: bash-3.2$ node blink.js

Output results (NOT as expected)

bash-3.2$ node blink.js 
Passed

Summary

Why are the results different? The results from the command-line usage are as expected, while the JS Object usage says "Passed" when it should say "Fail" and produce the output image.

marcelerz commented 9 years ago

Thank you for the well composed bug-report!

This was an error in the documentation. The first parameter is the typical Node error object for callbacks (when there was an error - not a difference). The second parameter, however, holds detailed information about the comparison - including the result. I updated the documentation and now the results are consistent. The code should look something like this:

#!/usr/bin/env node

BlinkDiff = require('blink-diff');

var diff = new BlinkDiff({
    imageAPath: 'people.png',
    imageBPath: 'people2.png',

    imageOutputPath: 'blink-diff-people.png',

    verbose: true
});

diff.run(function (error, result) {
    console.log(diff.hasPassed(result.code) ? 'Passed' : 'Failed with ' + result.differences + ' differences - ' + error);
});

The result is: blink-diff-people

Thanks! :+1: