UNPKG

2.91 kBTypeScriptView Raw
1// Type definitions for pngjs 6.0
2// Project: https://github.com/lukeapage/pngjs
3// Definitions by: Jason Cheatham <https://github.com/jason0x43>
4// Florian Imdahl <https://github.com/ffflorian>
5// Piotr Błażejewicz <https://github.com/peterblazejewicz>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
8/// <reference types="node" />
9
10import { Duplex } from 'stream';
11import { createDeflate } from 'zlib';
12
13export class PNG extends Duplex {
14 static adjustGamma(src: PNG): void;
15
16 static bitblt(
17 src: PNG,
18 dst: PNG,
19 srcX?: number,
20 srcY?: number,
21 width?: number,
22 height?: number,
23 deltaX?: number,
24 deltaY?: number,
25 ): void;
26
27 static sync: {
28 read(buffer: Buffer, options?: ParserOptions): PNGWithMetadata;
29 write(png: PNG, options?: PackerOptions): Buffer;
30 };
31
32 constructor(options?: PNGOptions);
33
34 data: Buffer;
35 gamma: number;
36 height: number;
37 width: number;
38
39 adjustGamma(): void;
40
41 bitblt(
42 dst: PNG,
43 srcX?: number,
44 srcY?: number,
45 width?: number,
46 height?: number,
47 deltaX?: number,
48 deltaY?: number,
49 ): PNG;
50
51 on(event: 'metadata', callback: (this: PNG, metadata: Metadata) => void): this;
52 on(event: 'parsed', callback: (this: PNG, data: Buffer) => void): this;
53 on(event: 'error', callback: (this: PNG, error: Error) => void): this;
54 on(event: 'close', callback: (this: PNG) => void): this;
55 on(event: string, callback: (this: PNG, ...args: any[]) => void): this;
56
57 pack(): PNG;
58
59 parse(data: string | Buffer, callback?: (error: Error, data: PNG) => void): PNG;
60}
61
62export interface BaseOptions {
63 fill?: boolean | undefined;
64 height?: number | undefined;
65 width?: number | undefined;
66}
67
68export interface ParserOptions {
69 checkCRC?: boolean | undefined;
70 skipRescale?: boolean | undefined;
71}
72
73export interface PackerOptions {
74 bgColor?: {
75 red: number;
76 green: number;
77 blue: number;
78 } | undefined;
79 bitDepth?: BitDepth | undefined;
80 colorType?: ColorType | undefined;
81 deflateChunkSize?: number | undefined;
82 deflateFactory?: typeof createDeflate | undefined;
83 deflateLevel?: number | undefined;
84 deflateStrategy?: number | undefined;
85 filterType?: number | number[] | undefined;
86 inputColorType?: ColorType | undefined;
87 inputHasAlpha?: boolean | undefined;
88}
89
90export type PNGOptions = BaseOptions & ParserOptions & PackerOptions;
91
92export type PNGWithMetadata = PNG & Metadata;
93
94export type ColorType = 0 | 2 | 4 | 6;
95
96export type BitDepth = 8 | 16;
97
98export interface Metadata {
99 alpha: boolean;
100 bpp: 1 | 2 | 3 | 4;
101 color: boolean;
102 colorType: ColorType;
103 depth: 1 | 2 | 4 | 8 | 16;
104 height: number;
105 interlace: boolean;
106 palette: boolean;
107 width: number;
108}