[pixelmatch] new package

This commit is contained in:
Oleg Repin
2017-11-22 16:30:56 +03:00
parent a4c2d3c7de
commit 0deb69ed5b
4 changed files with 81 additions and 0 deletions

30
types/pixelmatch/index.d.ts vendored Normal file
View File

@@ -0,0 +1,30 @@
// Type definitions for pixelmatch 4.0
// Project: https://github.com/mapbox/pixelmatch#readme
// Definitions by: Oleg Repin <https://github.com/iamolegga>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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 | undefined
): 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;

View File

@@ -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'));
}

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }