mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Add pica library type definition files (#41210)
* Add pica library type definition files * Fix pica library type definition files array and maximum line exceeds * Add pica library tests with parameterless constructor * Fix pica library pica resize buffer options src optional problem. - Add pica tests resizeBuffer with src options.
This commit is contained in:
committed by
Andrew Branch
parent
8f255f63e1
commit
a44ea7e379
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
// Type definitions for pica 5.1
|
||||
// Project: https://github.com/nodeca/pica
|
||||
// Definitions by: Hamit YILMAZ <https://github.com/hmtylmz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Pica {
|
||||
constructor(config?: PicaOptions);
|
||||
/**
|
||||
* Resize image from one canvas (or image) to another.
|
||||
* Sizes are taken from source and destination objects.
|
||||
* Result is Promise, resolved with to on success.
|
||||
* (!) If you need to process multiple images, do it sequentially to optimize CPU & memory use.
|
||||
* Pica already knows how to use multiple cores (if browser allows).
|
||||
*/
|
||||
resize(
|
||||
from: HTMLCanvasElement | HTMLImageElement | File | Blob,
|
||||
to: HTMLCanvasElement,
|
||||
options?: PicaResizeOptions
|
||||
): Promise<HTMLCanvasElement>;
|
||||
|
||||
/**
|
||||
* Convenience method, similar to canvas.toBlob(), but with promise interface & polyfill for old browsers.
|
||||
*/
|
||||
toBlob(
|
||||
canvas: HTMLCanvasElement,
|
||||
mimeType: string,
|
||||
quality?: number
|
||||
): Promise<Blob>;
|
||||
|
||||
/**
|
||||
* Supplementary method, not recommended for direct use.
|
||||
* Resize Uint8Array with raw RGBA bitmap (don't confuse with jpeg / png / ... binaries).
|
||||
* It does not use tiles & webworkers. Left for special cases when you really need to process raw binary data (for example, if you decode jpeg files "manually").
|
||||
*/
|
||||
resizeBuffer(
|
||||
options: PicaResizeBufferOptions
|
||||
): Promise<number[]>;
|
||||
}
|
||||
|
||||
interface PicaOptions {
|
||||
// tile width/height.
|
||||
// Images are processed by regions, to restrict peak memory use. Default 1024.
|
||||
tile?: number;
|
||||
// list of features to use.
|
||||
// Default is [ 'js', 'wasm', 'ww' ]. Can be [ 'js', 'wasm', 'cib', 'ww' ] or [ 'all' ].
|
||||
// Note, resize via createImageBitmap() ('cib') disabled by default due problems with quality.
|
||||
features?: string[];
|
||||
// cache timeout, ms. Webworkers create is not fast.
|
||||
// This option allow reuse webworkers effectively. Default 2000.
|
||||
idle?: number;
|
||||
// max webworkers pool size. Default is autodetected CPU count, but not more than 4.
|
||||
concurrency?: number;
|
||||
}
|
||||
|
||||
interface PicaResizeOptions {
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. By default it's not set. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Promise instance. If defined, current operation will be terminated on rejection.
|
||||
cancelToken?: string;
|
||||
}
|
||||
|
||||
interface PicaResizeBufferOptions {
|
||||
// Uint8Array with source data.
|
||||
src: number[];
|
||||
// src image width.
|
||||
width: number;
|
||||
// src image height.
|
||||
height: number;
|
||||
// output width, >=0, in pixels.
|
||||
toWidth: number;
|
||||
// output height, >=0, in pixels.
|
||||
toHeigh: number;
|
||||
// 0..3. Default = 3 (lanczos, win=3).
|
||||
quality?: number;
|
||||
// use alpha channel. Default = false.
|
||||
alpha?: boolean;
|
||||
// >=0, in percents. Default = 0 (off). Usually between 50 to 100 is good.
|
||||
unsharpAmount?: number;
|
||||
// 0.5..2.0. Radius of Gaussian blur.
|
||||
// If it is less than 0.5, Unsharp Mask is off. Big values are clamped to 2.0.
|
||||
unsharpRadius?: number;
|
||||
// 0..255. Default = 0. Threshold for applying unsharp mask.
|
||||
unsharpThreshold?: number;
|
||||
// Optional. Output buffer to write data, if you don't wish pica to create new one.
|
||||
dest?: string;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
let resizer: Pica = new Pica();
|
||||
|
||||
let picaOptions: PicaOptions = { features: ['js', 'wasm', 'ww', 'cib'] };
|
||||
let resizerWithOptions: Pica = new Pica(picaOptions);
|
||||
|
||||
let image: HTMLImageElement = document.createElement('img');
|
||||
image.width = 100;
|
||||
image.height = 100;
|
||||
|
||||
let canvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
canvas.width = 100;
|
||||
canvas.height = 100;
|
||||
|
||||
// Resize image
|
||||
resizer.resize(image, canvas);
|
||||
resizerWithOptions.resize(image, canvas);
|
||||
|
||||
// Resize image with options
|
||||
let resizeOptions: PicaResizeOptions = {
|
||||
quality: 9
|
||||
};
|
||||
resizer.resize(image, canvas, resizeOptions);
|
||||
resizerWithOptions.resize(image, canvas, resizeOptions);
|
||||
|
||||
// Blob canvas
|
||||
resizer.toBlob(canvas, 'image/png');
|
||||
resizerWithOptions.toBlob(canvas, 'image/png');
|
||||
|
||||
// Blob canvas with quality
|
||||
resizer.toBlob(canvas, 'image/png', 9);
|
||||
resizerWithOptions.toBlob(canvas, 'image/png', 9);
|
||||
|
||||
// Resize buffer
|
||||
let resizeBufferSrc: number[] = [21, 31];
|
||||
let resizeBufferOptions: PicaResizeBufferOptions = {
|
||||
src: resizeBufferSrc,
|
||||
width: 100,
|
||||
height: 100,
|
||||
toWidth: 50,
|
||||
toHeigh: 50,
|
||||
};
|
||||
resizer.resizeBuffer(resizeBufferOptions);
|
||||
resizerWithOptions.resizeBuffer(resizeBufferOptions);
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pica-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user