0.0.3 • Published 3 years ago
diff-image v0.0.3
diff-image
Use pixelmatch to compare two images in a browser environment.
Install
npm install diff-image --save
or
yarn add diff-imageUse
import DiffImage from "diff-image";
const img1 =
"https://raw.githubusercontent.com/mapbox/pixelmatch/main/test/fixtures/1a.png";
const img2 =
"https://raw.githubusercontent.com/mapbox/pixelmatch/main/test/fixtures/1b.png";
async function main() {
const diffImageIns = new DiffImage();
let diffCount = await diffImageIns.diff(img1, img2);
console.log("diffCount", diffCount);
}
main();Options
diff(img1, img2, options)
img1type string
img2type string
options- For more information, see https://github.com/mapbox/pixelmatch
threshold— Matching threshold, ranges from0to1. Smaller values make the comparison more sensitive.0.1by default.includeAA— Iftrue, disables detecting and ignoring anti-aliased pixels.falseby default.alpha— Blending factor of unchanged pixels in the diff output. Ranges from0for pure white to1for original brightness.0.1by default.aaColor— The color of anti-aliased pixels in the diff output in[R, G, B]format.[255, 255, 0]by default.diffColor— The color of differing pixels in the diff output in[R, G, B]format.[255, 0, 0]by default.diffColorAlt— An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts. If not provided, all differing pixels use the color specified bydiffColor.nullby default.diffMask— Draw the diff over a transparent background (a mask), rather than over the original image. Will not draw anti-aliased pixels (if detected).