Skip to content

Commit 61c03d5

Browse files
Add TypeScript declaration file
1 parent 32b517e commit 61c03d5

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

index.d.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Describes a region to boost. A usage example of this is to take into account
3+
* faces in the image. See `smartcrop-cli` for an example on how to integrate
4+
* face detection in Node.js using ImageMagick with `smartcrop-gm`.
5+
* @see {@link https://github.com/jwagner/smartcrop.js#boost}
6+
* @see {@link https://github.com/jwagner/smartcrop-cli}
7+
*/
8+
export interface Boost {
9+
x: number;
10+
y: number;
11+
width: number;
12+
height: number;
13+
weight: number;
14+
}
15+
16+
/**
17+
* All of the documented crop options. Note that there are many more (for now
18+
* undocumented) options available. Check the source and be advised that they
19+
* might change in the future.
20+
* @see {@link https://github.com/jwagner/smartcrop.js#cropoptions}
21+
* @see {@link https://github.com/jwagner/smartcrop.js/blob/master/smartcrop.js#L32}
22+
*/
23+
export interface CropOptions {
24+
minScale?: number;
25+
width: number;
26+
height: number;
27+
boost?: Boost[];
28+
ruleOfThirds?: boolean;
29+
debug?: boolean;
30+
}
31+
32+
/**
33+
* Result of the promise returned by `smartcrop.crop`. Contains a single
34+
* individual crop that can then be used by `sharp` to extract your image.
35+
* @see {@link https://github.com/jwagner/smartcrop.js#cropresult}
36+
* @see {@link https://github.com/jwagner/smartcrop.js#crop}
37+
*/
38+
export interface CropResult {
39+
topCrop: { x: number; y: number; width: number; height: number; };
40+
}
41+
42+
/**
43+
* Find the best crop for *image* using *options*.
44+
* @param image - A string (path to file) or buffer of image source.
45+
* @param cropOptions - Crop options based to `smartcrop.js`.
46+
* @return Promise that resolves with the final crop result that can then be
47+
* used by `sharp` to extract your final image.
48+
*/
49+
export function crop(image: Buffer | string, cropOptions: CropOptions): Promise<CropResult>;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "smartcrop-sharp",
33
"version": "2.0.3",
44
"description": "smartcrop adapter for sharp",
5+
"types": "index.d.ts",
56
"main": "index.js",
67
"scripts": {
78
"test": "eslint index.js test/test.js && mocha --reporter spec"

0 commit comments

Comments
 (0)