Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Added image-diff executable
Browse files Browse the repository at this point in the history
  • Loading branch information
twolfson committed Mar 16, 2016
1 parent f2ad6d7 commit 68faac8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# image-diff changelog
1.5.0 - Added `image-diff` executable

1.4.0 - Moved from `crop` to `extent`. Fixes #32 indirectly

1.3.0 - Fixed support for fractional differences via @jacobp100 in #29
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@ Create an differential image between multiple images
- For example, if an image is `+` and we diff with `-`, then the image will have `|` be red but also contain a faded `-`
- By default, this options is `false` meaning a shadow will not be drawn

### CLI usage
We offer an `image-diff` executable to diff from the CLI. When images match, its exit code will be `0`. When they don't match, then it will be non-zero (e.g. `1`).

```
$ image-diff --help
Usage: image-diff [options] <actual-image> <expected-image> [diff-image]
Options:
-h, --help output usage information
-V, --version output the version number
--shadow Draw a shadow of unchanges parts on diff image
```

Example usage:

```bash
# Images don't match
image-diff checkerboard.png white.png diff.png
echo $?
# 1
# We can look at `diff.png` for the diff result

# Images do match
image-diff checkerboard.png white.png
echo $?
# 0
```

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via [grunt](https://github.com/gruntjs/grunt) and test via `npm test`.

Expand Down
39 changes: 39 additions & 0 deletions bin/image-diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node
// Load in our dependencies
var program = require('commander');
var pkg = require('../package.json');
var imageDiff = require('../');

// Configure our CLI
program.name = pkg.name;
program
.version(pkg.version)
.usage('[options] <actual-image> <expected-image> [diff-image]')
.option('--shadow', 'Draw a shadow of unchanges parts on diff image')
.action(function handleRun (actualImage, expectedImage, diffImage, program) {
// If there is no program, then assume diffImage was left out
if (program === undefined) {
program = diffImage;
diffImage = undefined;
}

// Run our diff
imageDiff({
actualImage: actualImage,
diffImage: diffImage,
expectedImage: expectedImage,
shadow: program.shadow
}, function handleImageDiff (err, imagesAreSame) {
// If there was an error, throw it
if (err) {
throw err;
}

// Otherwise, exit based on the result
var exitCode = imagesAreSame ? 0 : 1;
process.exit(exitCode);
});
});

// Parse our CLI arguments
program.parse(process.argv);
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"url": "https://github.com/uber/image-diff/blob/master/LICENSE-MIT"
}
],
"bin": {
"image-diff": "bin/image-diff"
},
"main": "lib/image-diff",
"engines": {
"node": ">= 0.8.0"
Expand All @@ -31,6 +34,7 @@
"dependencies": {
"async": "~0.2.9",
"buffered-spawn": "~1.1.1",
"commander": "~2.9.0",
"gm": "~1.13.3",
"mkdirp": "~0.3.5",
"tmp": "0.0.23"
Expand Down

0 comments on commit 68faac8

Please sign in to comment.