Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Create image differential between two images.
- `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](https://github.com/mapbox/pixelmatch#api).
- `options` - _Optional_ - An object to pass through [BlazeDiff](https://www.blazediff.dev/docs/core#api-reference).

#### `ImgDiffResult`

Expand Down
40 changes: 7 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@
},
"homepage": "https://github.com/reg-viz/img-diff-js#readme",
"dependencies": {
"@blazediff/core": "^1.9.0",
"decode-tiff": "^0.2.0",
"jpeg-js": "^0.4.2",
"mkdirp": "^1.0.4",
"pixelmatch": "^5.2.1",
"pngjs": "^7.0.0"
},
"devDependencies": {
"@types/jest": "29.5.14",
"@types/mkdirp": "^1.0.1",
"@types/node": "^20.0.0",
"@types/pixelmatch": "^5.2.2",
"@types/pngjs": "^6.0.0",
"@types/rimraf": "4.0.5",
"cp-file": "11.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import pixelmatch, { type PixelmatchOptions } from "pixelmatch";
import { diff as blazediff, type CoreOptions as BlazeDiffOptions } from "@blazediff/core";
import { PNG } from "pngjs";
import mkdirp from "mkdirp";

Expand Down Expand Up @@ -40,16 +40,16 @@ function compare(
img2: ImageData,
diffFilename?: string,
generateOnlyDiffFile: boolean = false,
options: PixelmatchOptions = { threshold: 0.1, includeAA: false },
options: BlazeDiffOptions = { threshold: 0.1, includeAA: false },
): Promise<ImgDiffResult> {
const { dataList, width, height } = expand(img1, img2);
const diff = new PNG({ width, height });
const pmOpt: PixelmatchOptions = {
const pmOpt: BlazeDiffOptions = {
threshold: 0,
...options,
};

const count = pixelmatch(dataList[0], dataList[1], diff.data, width, height, pmOpt);
const count = blazediff(dataList[0], dataList[1], diff.data, width, height, pmOpt);
const imagesAreSame = count === 0;
const result = {
width,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PixelmatchOptions } from "pixelmatch";
import type { CoreOptions as BlazeDiffOptions } from "@blazediff/core";

export interface ImageData {
width: number;
Expand All @@ -15,7 +15,7 @@ export interface ImgDiffOptions {
expectedFilename: string;
diffFilename?: string;
generateOnlyDiffFile?: boolean;
options?: PixelmatchOptions;
options?: BlazeDiffOptions;
}

export interface ImgDiffResult {
Expand Down