mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 21:31:12 +08:00
[pixelmatch] new package
This commit is contained in:
30
types/pixelmatch/index.d.ts
vendored
Normal file
30
types/pixelmatch/index.d.ts
vendored
Normal 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;
|
||||
27
types/pixelmatch/pixelmatch-tests.ts
Normal file
27
types/pixelmatch/pixelmatch-tests.ts
Normal 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'));
|
||||
}
|
||||
23
types/pixelmatch/tsconfig.json
Normal file
23
types/pixelmatch/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/pixelmatch/tslint.json
Normal file
1
types/pixelmatch/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user