DefinitelyTyped/types/pixelmatch/pixelmatch-tests.ts
Piotr Błażejewicz (Peter Blazejewicz) f633bcdf25
feat(pixelmatch): update to version 5.1 (#43096)
- new `diffMask` option
- rewrite default value documentation for options
- test amend
- apply DT Prettier styling to source files

https://github.com/mapbox/pixelmatch/compare/v5.0.0...v5.1.0

Thanks!
2020-03-13 18:41:27 -07:00

30 lines
743 B
TypeScript

/**
* This test code taken from pixelmatch example usage.
* https://github.com/mapbox/pixelmatch#example-usage
*/
import * as fs from 'fs';
import pixelmatch = require('pixelmatch');
import { PNG } from 'pngjs';
const img1 = fs
.createReadStream('img1.png')
.pipe(new PNG())
.on('parsed', doneReading);
const img2 = fs
.createReadStream('img2.png')
.pipe(new PNG())
.on('parsed', doneReading);
let filesRead = 0;
function doneReading() {
if (++filesRead < 2) return;
const diff = new PNG({ width: img1.width, height: img1.height });
pixelmatch(img1.data, img2.data, diff.data, img1.width, img1.height, { threshold: 0.1, diffMask: true });
diff.pack().pipe(fs.createWriteStream('diff.png'));
}