UNPKG

@thi.ng/imago

Version:

JSON & API-based declarative and extensible image processing trees/pipelines

52 lines 2.43 kB
import sharp, { type Sharp } from "sharp"; import type { BufferLike, ImgProcCtx, ImgProcOpts, IntBufferLike, ProcSpec } from "./api.js"; export declare const LOGGER: import("@thi.ng/logger").ProxyLogger; /** * Main API function. Takes an image input (file path, Buffer, ArrayBuffer, * thi.ng/pixel IntBuffer or an existing Sharp instance) and applies given * processing pipeline specs in sequence. Returns a promise of final processed * image, input metadata (if any), an environment object of arbitrary data * (likely produced by custom ops/processors) and an object of all written * output paths (keyed by each output's {@link OutputSpec.id}). The process * pipeline can be additionally configured via provided options. * * @remarks * The `parentCtx` arg is internal use only (nested processors)! * * @param src * @param specs * @param opts * @param parentCtx */ export declare const processImage: (src: string | BufferLike | ArrayBuffer | IntBufferLike | Sharp, specs: ProcSpec[], opts?: Partial<ImgProcOpts>, parentCtx?: ImgProcCtx) => Promise<{ img: sharp.Sharp; meta: sharp.Metadata; env: import("@thi.ng/api").IObjectOf<any>; outputs: Record<string, string | Buffer<ArrayBufferLike>>; outputMeta: Record<string, Record<string, any>>; }>; /** * Extensible polymorphic function performing a single image processing step. * * @remarks * The function returns a tuple of `[img, bakeFlag]`. If the flag (2nd value) * is true, the returned image will be serialized/baked to an internal buffer * (also wiping any EXIF!) after the current processing step and then used as * input for the next processing step. * * Due to most ops in sharp's API merely setting internal state rather than * applying changes directly, all size or channel changing procs will require * "baking" in order to produce predictable results... The {@link processImage} * function checks this flag after each processing step and its down to each * processor to determine if baking is required or not... * * To add support for a custom operation/processor, call: `processor.add("myid", * myProcessor)`. Note that registered IDs should be unique (but can also * override existing impls). * * @param spec * @param img * @param ctx **/ export declare const processor: import("@thi.ng/defmulti").MultiFn3<ProcSpec, sharp.Sharp, ImgProcCtx, Promise<[sharp.Sharp, boolean]>>; //# sourceMappingURL=proc.d.ts.map