diff --git a/types/pixelmatch/index.d.ts b/types/pixelmatch/index.d.ts new file mode 100644 index 0000000000..0a2e4277ac --- /dev/null +++ b/types/pixelmatch/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for pixelmatch 4.0 +// Project: https://github.com/mapbox/pixelmatch#readme +// Definitions by: Oleg Repin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare function Pixelmatch( + /** Image data of the first image to compare. Note: image dimensions must be equal. */ + img1: Buffer | Uint8Array, + /** Image data of the second image to compare. Note: image dimensions must be equal. */ + img2: Buffer | Uint8Array, + /** Image data to write the diff to, or null if don't need a diff image. */ + output: Buffer | Uint8Array | null, + /** Width of the images. Note that all three images need to have the same dimensions. */ + width: number, + /** Height of the images. Note that all three images need to have the same dimensions. */ + height: number, + /** Options. */ + options?: Options, +): number; + +interface Options { + /** Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default. */ + readonly threshold?: number; + /** If true, disables detecting and ignoring anti-aliased pixels. false by default. */ + readonly includeAA?: boolean; +} + +export = Pixelmatch; diff --git a/types/pixelmatch/pixelmatch-tests.ts b/types/pixelmatch/pixelmatch-tests.ts new file mode 100644 index 0000000000..dc49f7f326 --- /dev/null +++ b/types/pixelmatch/pixelmatch-tests.ts @@ -0,0 +1,27 @@ +/** + * 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}); + + diff.pack().pipe(fs.createWriteStream('diff.png')); +} diff --git a/types/pixelmatch/tsconfig.json b/types/pixelmatch/tsconfig.json new file mode 100644 index 0000000000..02115e3fdc --- /dev/null +++ b/types/pixelmatch/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pixelmatch-tests.ts" + ] +} diff --git a/types/pixelmatch/tslint.json b/types/pixelmatch/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pixelmatch/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }