mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
feat(png-img): type definition for v2.3 (#43750)
- declaration file - tests https://github.com/gemini-testing/png-img#api Thanks!
This commit is contained in:
committed by
GitHub
parent
fe4a8005c5
commit
776caac7f5
83
types/png-img/index.d.ts
vendored
Normal file
83
types/png-img/index.d.ts
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
// Type definitions for png-img 2.3
|
||||
// Project: https://github.com/gemini-testing/png-img
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare class PngImg {
|
||||
/**
|
||||
* Create PngImg object from passed buffer with image
|
||||
*/
|
||||
constructor(buffer: Buffer);
|
||||
|
||||
/**
|
||||
* Get image size as an object.
|
||||
*/
|
||||
size(): Size;
|
||||
|
||||
/**
|
||||
* Get pixel color and alpha.
|
||||
*/
|
||||
get(x: number, y: number): Color;
|
||||
|
||||
/**
|
||||
* Fill region with passed color. Modifies current image.
|
||||
* Color can be {r,g,b,a} object or as a '#XXXXXX' string
|
||||
*/
|
||||
fill(offsetX: number, offsetY: number, width: number, height: number, color: Color | string): this;
|
||||
|
||||
/**
|
||||
* Same as fill(x, y, 1, 1, color)
|
||||
* (shorthand)
|
||||
*/
|
||||
set(x: number, y: number, color: Color | string): this;
|
||||
|
||||
/**
|
||||
* Crop image. Modifies current image.
|
||||
* Throws if new image is not inside the current image.
|
||||
*/
|
||||
crop(offsetX: number, offsetY: number, width: number, height: number): this;
|
||||
|
||||
/**
|
||||
* Sets new image size. Modifies current image.
|
||||
* If new size is less or equal than current size, than crop will be performed.
|
||||
*/
|
||||
setSize(width: number, height: number): this;
|
||||
|
||||
/**
|
||||
* Inserts image into specified place.
|
||||
*/
|
||||
insert(img: PngImg, offsetX: number, offsetY: number): this;
|
||||
|
||||
/**
|
||||
* Rotates image 90 degrees clockwise
|
||||
*/
|
||||
rotateRight(): this;
|
||||
|
||||
/**
|
||||
* Rotates image 90 degress counterclockwise
|
||||
*/
|
||||
rotateLeft(): this;
|
||||
|
||||
/**
|
||||
* Save image to file. Asynchronous operation.
|
||||
* @param file - path to file to save image
|
||||
* @param callback - will be called after save operation finish or on error
|
||||
*/
|
||||
save(file: string, callback: (error: Error) => void): void;
|
||||
}
|
||||
|
||||
interface Size {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
interface Color {
|
||||
r: number;
|
||||
g: number;
|
||||
b: number;
|
||||
a: number;
|
||||
}
|
||||
|
||||
export = PngImg;
|
||||
20
types/png-img/png-img-tests.ts
Normal file
20
types/png-img/png-img-tests.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs = require('fs');
|
||||
import PngImg = require('png-img');
|
||||
|
||||
const buf = fs.readFileSync('path/to/img.png');
|
||||
const img = new PngImg(buf);
|
||||
const otherImg = new PngImg(buf);
|
||||
img.size(); // $ExpectType Size
|
||||
img.get(0, 0); // $ExpectType Color
|
||||
img.fill(0, 0, 16, 16, '#00ffFF') // fill with cyan
|
||||
.fill(16, 16, 16, 16, { r: 0, g: 255, b: 255, a: 127 });
|
||||
img.crop(0, 0, 16, 16).crop(8, 8, 8, 8);
|
||||
img.setSize(img.size().width, img.size().height + otherImg.size().height).insert(otherImg, 0, img.size().height);
|
||||
|
||||
img.save('path/to/file.png', error => {
|
||||
if (error) {
|
||||
console.error('Error:', error);
|
||||
} else {
|
||||
console.log('OK');
|
||||
}
|
||||
});
|
||||
23
types/png-img/tsconfig.json
Normal file
23
types/png-img/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"png-img-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/png-img/tslint.json
Normal file
1
types/png-img/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user