0.5.4 • Published 2 months ago

img-diff-js v0.5.4

Weekly downloads
25,615
License
MIT
Repository
github
Last release
2 months ago

img-diff-js

github actions npm version codecov License: MIT

:art: Node.js library to compare 2 images without native libs.

ActualExpectedDifference
actualexpecteddiff

Install

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));

API Usage

imgDiff(opt: ImgDiffOptions): Promise<ImgDiffResult>

Create image differential between two images.

ImgDiffOptions

{
  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 difference
  • options - Optional - An object to pass through pixelmatch.

ImgDiffResult

{
  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.

Available format

The following codecs are available for input image files.

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.

Contribute

PR or issue is welcome :)

Setup

yarn

Test

yarn test

Run benchmark script

yarn run perf

License

MIT License. See LICENSE under this repository.

0.5.4

2 months ago

0.5.3

2 months ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

4 years ago

0.4.1

6 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago