uber / image-diff
- суббота, 30 июля 2016 г. в 03:16:42
JavaScript
Create image differential between two images
Create image differential between two images
This was created as part of a visual regression project.
image-diff
depends on ImageMagick.
Please install this before continuing.
Install the module with: npm install image-diff
var imageDiff = require('image-diff');
imageDiff({
actualImage: 'checkerboard.png',
expectedImage: 'white.png',
diffImage: 'difference.png',
}, function (err, imagesAreSame) {
// error will be any errors that occurred
// imagesAreSame is a boolean whether the images were the same or not
// diffImage will have an image which highlights differences
});
image-diff
exposes the function imageDiff
as its export.
imageDiff(options, cb)
Create an differential image between multiple images
Object
String
- Path to actual image file
String
- Path to expected image file
String
- Optional path to output differential imageBoolean
- Optional flag to indicate if we should draw a shadow of the unchanged parts of the images
+
and we diff with -
, then the image will have |
be red but also contain a faded -
false
meaning a shadow will not be drawnFunction
- Error-first function to handle diff result
cb
should have the signature function (err, imagesAreSame)
Error|null
- If there was an error in diffing, this will be itBoolean
- Indicates that images are same or notimageDiff.getFullResult(options, cb)
Same as imageDiff
but yields a fuller result
Object
- See imageDiff#options
Function
- Error-first function to handle diff result
cb
should have the signature function (err, result)
Error|null
- If there was an error in diffing, this will be itObject
Float
- Root mean square pixel difference across all pixels
Float
- Normalized total difference
Example:
var imageDiff = require('image-diff');
imageDiff.getFullResult({
actualImage: 'checkerboard.png',
expectedImage: 'white.png',
diffImage: 'difference.png',
}, function (err, result) {
// result = {total: 46340.2, difference: 0.707107}
});
imageDiff.getRawResult(options, cb)
Same as imageDiff
but yields raw CLI result
Object
- See imageDiff#options
Function
- Error-first function to handle diff result
cb
should have the signature function (err, result)
Error|null
- If there was an error in diffing, this will be itString
- Result from ImageMagick's compare
command
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:
# 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
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 and test via npm test
.
The font used for the example image is Arial 30pt bold and Courier New 38pt.
Copyright (c) 2013 Uber
Licensed under the MIT license.