🎨 Node.js library to compare 2 images without native libs.
Actual | Expected | Difference |
---|---|---|
![]() |
![]() |
![]() |
npm install img-diff-js
const { imgDiff } = require('img-diff-js');
imgDiff({
actualFilename: 'example/actual.png',
expectedFilename: 'example/expected.png',
diffFilename: 'example/diff.png',
}).then(result => console.log(result));
Create image differential between two images.
{
actualFilename: string;
expectedFilename: string;
diffFilename?: string;
generateOnlyDiffFile?: boolean; // default false
options?: {
threshold?: number; // default 0.1
includeAA?: boolean; // default false
}
}
actualFilename
- Required - Path to actual image file.expectedFilename
- Required - Path to expected image file.diffFilename
- Optional - Path to differential image file. If omitted,imgDiff
does not output image file.generateOnlyDiffFile
- Optional - Generate only files with differenceoptions
- Optional - An object to pass through pixelmatch.
{
width: number;
height: number;
imagesAreSame: boolean;
diffCount: number;
}
width
- Differential image's width.height
- Differential image's height.imagesAreSame
- It'll be true only if 2 images are same perfectly.diffCount
- The number of differential pixels.
The following codecs are available for input image files.
- png
- jpeg
- tiff (limited. See https://github.com/Quramy/decode-tiff#compatibility )
- bmp
imgDiff
detects the input image format from it's extension name. For example, if the input file name ends with ".jpeg", imgDiff
attempts to decode in JPEG way regardless of the actual file format.
The output image format is PNG only.
case name | img-diff-js | image-difference | image-diff |
---|---|---|---|
50 same dimension PNGs | 936 msec | 11018 msec | 16539 msec |
50 different dimension PNGs | 715 msec | 16077 msec | 16639 msec |
50 same dimension JPEGs | 1076 msec | 10910 msec | 19078 msec |
The above table was captured under Travis-CI. If you want the latest result, check the raw log.
PR or issue is welcome :)
yarn
yarn test
yarn run perf
MIT License. See LICENSE under this repository.