|
| 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>; |
0 commit comments