1
12
13
14export interface SharpInstance {
15 rotate(): SharpInstance;
16 resize(opts: { width: number; withoutEnlargement?: boolean }): SharpInstance;
17 metadata(): Promise<{ width?: number; height?: number; orientation?: number }>;
18 toFormat(name: string): SharpInstance;
19 png(): SharpInstance;
20 toBuffer(): Promise<Buffer>;
21}
22
23
25export interface SharpOptions {
26 limitInputPixels?: number;
27}
28
29export type SharpConstructor = (input: string | Buffer, options?: SharpOptions) => SharpInstance;
30
31let cached: SharpConstructor | null = null;
32
33export async function getSharp(): Promise<SharpConstructor> {
34 if (cached) return cached;
35
36 const mod: any = await import("sharp");
37 const fn: SharpConstructor = (mod?.default ?? mod) as SharpConstructor;
38 cached = fn;
39 return fn;
40}
41