import { Readable } from 'node:stream'; import { F as File, g as FileReturn, B as BaseStorage } from "../packem_shared/storage.d-C9EdfTf1.js"; import { I as ImageTransformerConfig, T as TransformResult, R as ResizeOptions, C as CropOptions, g as RotateOptions, h as ImageFormat, i as TransformOptions, S as SharpenOptions, j as BlurOptions, k as MedianOptions, l as CLAHEOptions, m as ConvolveOptions, n as ThresholdOptions, o as BooleanOptions, L as LinearOptions, p as RecombineOptions, q as ModulateOptions, r as TintOptions, G as GreyscaleOptions, s as ColourspaceOptions, E as ExtractChannelOptions, J as JoinChannelOptions, t as BandboolOptions, u as AffineOptions, D as DilateOptions, v as ErodeOptions, P as PipelineColourspaceOptions, w as ToColourspaceOptions, x as RemoveAlphaOptions, y as EnsureAlphaOptions, z as TransformationStep, B as BaseTransformer } from "../packem_shared/types.d-D1TIRqKW.js"; import 'node:timers'; import 'node:crypto'; import 'node:http'; import 'lru-cache'; /** * Image transformer that uses storage backends to retrieve and transform images. * @template TFile The file type used by this transformer. * @template TFileReturn The return type for file retrieval operations. * * Supports URL-based transformations with query parameters for on-demand image processing. * @example * ```ts * const transformer = new ImageTransformer(storage, { * maxImageSize: 10 * 1024 * 1024, // 10MB * cache: new Map() * }); * * // Programmatic usage - resize an image * const result = await transformer.resize('image-id', { * width: 800, * height: 600, * fit: 'cover' * }); * * // URL-based transformations * // GET /files/image-id?width=300&height=200&fit=cover&quality=80 * // GET /files/image-id?width=800&quality=90&lossless=true * ``` * * ## Supported Query Parameters * * - `width`: Width in pixels (Number) * - `height`: Height in pixels (Number) * - `fit`: Resize fit mode - cover/contain/fill/inside/outside * - `position`: Position for cover/contain fits - center/top/right/bottom/left etc. * - `quality`: Quality for JPEG/WebP (0-100) * - `lossless`: Use lossless compression for WebP (Boolean) * - `effort`: CPU effort for AVIF (0-10, higher = slower but better) * - `alphaQuality`: Quality of alpha layer for WebP (0-100) * - `loop`: GIF animation iterations, 0 for infinite (Number) * - `delay`: GIF delay between frames in milliseconds (Number) */ declare class ImageTransformer extends BaseTransformer, TFile, TFileReturn> { /** * Creates a new ImageTransformer instance. * @param storage The storage backend for retrieving and storing image files. * @param config Configuration options for image transformation including cache settings and size limits. */ constructor(storage: BaseStorage, config?: ImageTransformerConfig); /** * Returns a sharp() invocation that applies the transformer's configured decompression-bomb defenses. */ private openImage; /** * Resizes an image to specified dimensions with optional fit mode. * @param fileId Unique identifier of the image file to resize. * @param options Resize options including width, height, and fit mode. * @returns Promise resolving to transformed image result. */ resize(fileId: string, options: ResizeOptions): Promise>; /** * Crops an image to the specified region. * @param fileId Unique identifier of the image file to crop. * @param options Crop options including region coordinates. * @returns Promise resolving to transformed image result. */ crop(fileId: string, options: CropOptions): Promise>; /** * Rotates an image by the specified angle. * @param fileId Unique identifier of the image file to rotate. * @param options Rotate options including angle. * @returns Promise resolving to transformed image result. */ rotate(fileId: string, options: RotateOptions): Promise>; /** * Converts an image to the specified format. * @param fileId Unique identifier of the image file to convert. * @param format Target image format (e.g., "jpeg", "png", "webp"). * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ convertFormat(fileId: string, format: ImageFormat, options?: TransformOptions): Promise>; /** * Applies sharpening filter to an image. * @param fileId Unique identifier of the image file to sharpen. * @param options Sharpen options including sigma and flat/jagged threshold. * @returns Promise resolving to transformed image result. */ sharpen(fileId: string, options?: SharpenOptions): Promise>; /** * Applies blurring filter to an image. * @param fileId Unique identifier of the image file to blur. * @param options Blur options including sigma. * @returns Promise resolving to transformed image result. */ blur(fileId: string, options?: BlurOptions): Promise>; /** * Applies median filter to an image for noise reduction. * @param fileId Unique identifier of the image file to process. * @param options Median filter options including radius. * @returns Promise resolving to transformed image result. */ median(fileId: string, options?: MedianOptions): Promise>; /** * Applies CLAHE (Contrast Limited Adaptive Histogram Equalization) to an image. * @param fileId Unique identifier of the image file to process. * @param options CLAHE options including width, height, and maxSlope. * @returns Promise resolving to transformed image result. */ clahe(fileId: string, options?: CLAHEOptions): Promise>; /** * Applies convolution kernel to an image. * @param fileId Unique identifier of the image file to process. * @param options Convolve options including kernel matrix. * @returns Promise resolving to transformed image result. */ convolve(fileId: string, options: ConvolveOptions): Promise>; /** * Applies thresholding to an image to create a binary image. * @param fileId Unique identifier of the image file to process. * @param options Threshold options including threshold value. * @returns Promise resolving to transformed image result. */ threshold(fileId: string, options?: ThresholdOptions): Promise>; /** * Applies boolean operation to an image. * @param fileId Unique identifier of the image file to process. * @param options Boolean operation options including operator and operand. * @returns Promise resolving to transformed image result. */ boolean(fileId: string, options: BooleanOptions): Promise>; /** * Applies linear transformation to an image. * @param fileId Unique identifier of the image file to process. * @param options Linear transformation options including a and b coefficients. * @returns Promise resolving to transformed image result. */ linear(fileId: string, options: LinearOptions): Promise>; /** * Applies recombine transformation to an image using a matrix. * @param fileId Unique identifier of the image file to process. * @param options Recombine options including matrix coefficients. * @returns Promise resolving to transformed image result. */ recombine(fileId: string, options: RecombineOptions): Promise>; /** * Applies modulation (brightness, saturation, hue) to an image. * @param fileId Unique identifier of the image file to process. * @param options Modulate options including brightness, saturation, and hue. * @returns Promise resolving to transformed image result. */ modulate(fileId: string, options: ModulateOptions): Promise>; /** * Applies tinting to an image. * @param fileId Unique identifier of the image file to process. * @param options Tint options including RGB color values. * @returns Promise resolving to transformed image result. */ tint(fileId: string, options: TintOptions): Promise>; /** * Converts an image to greyscale. * @param fileId Unique identifier of the image file to convert. * @param options Greyscale conversion options. * @returns Promise resolving to transformed image result. */ greyscale(fileId: string, options?: GreyscaleOptions): Promise>; /** * Converts an image to a different colourspace. * @param fileId Unique identifier of the image file to convert. * @param options Colourspace conversion options including target colourspace. * @returns Promise resolving to transformed image result. */ colourspace(fileId: string, options: ColourspaceOptions): Promise>; /** * Extracts a specific channel from an image. * @param fileId Unique identifier of the image file to process. * @param options Extract channel options including channel index. * @returns Promise resolving to transformed image result. */ extractChannel(fileId: string, options: ExtractChannelOptions): Promise>; /** * Joins channels to an image. * @param fileId Unique identifier of the image file to process. * @param options Join channel options including channel sources. * @returns Promise resolving to transformed image result. */ joinChannel(fileId: string, options: JoinChannelOptions): Promise>; /** * Applies band boolean operation to an image. * @param fileId Unique identifier of the image file to process. * @param options Band boolean options including operator. * @returns Promise resolving to transformed image result. */ bandbool(fileId: string, options: BandboolOptions): Promise>; /** * Auto-orients an image based on EXIF orientation data. * @param fileId Unique identifier of the image file to orient. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ autoOrient(fileId: string, options?: TransformOptions): Promise>; /** * Flips an image vertically. * @param fileId Unique identifier of the image file to flip. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ flip(fileId: string, options?: TransformOptions): Promise>; /** * Flops an image horizontally. * @param fileId Unique identifier of the image file to flop. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ flop(fileId: string, options?: TransformOptions): Promise>; /** * Flattens an image alpha channel onto a background color. * @param fileId Unique identifier of the image file to flatten. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ flatten(fileId: string, options?: TransformOptions): Promise>; /** * Unflattens an image alpha channel. * @param fileId Unique identifier of the image file to unflatten. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ unflatten(fileId: string, options?: TransformOptions): Promise>; /** * Applies gamma correction to an image. * @param fileId Unique identifier of the image file to process. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ gamma(fileId: string, options?: TransformOptions): Promise>; /** * Negates (inverts) an image. * @param fileId Unique identifier of the image file to negate. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ negate(fileId: string, options?: TransformOptions): Promise>; /** * Normalises an image by enhancing contrast. * @param fileId Unique identifier of the image file to normalise. * @param options Additional transform options. * @returns Promise resolving to transformed image result. */ normalise(fileId: string, options?: TransformOptions): Promise>; /** * Applies affine transformation to an image. * @param fileId Unique identifier of the image file to transform. * @param options Affine transformation options including matrix. * @returns Promise resolving to transformed image result. */ affine(fileId: string, options: AffineOptions): Promise>; /** * Applies dilation (morphological operation) to an image. * @param fileId Unique identifier of the image file to process. * @param options Dilate options including iterations. * @returns Promise resolving to transformed image result. */ dilate(fileId: string, options?: DilateOptions): Promise>; /** * Applies erosion (morphological operation) to an image. * @param fileId Unique identifier of the image file to process. * @param options Erode options including iterations. * @returns Promise resolving to transformed image result. */ erode(fileId: string, options?: ErodeOptions): Promise>; /** * Sets pipeline colourspace for an image. * @param fileId Unique identifier of the image file to process. * @param options Pipeline colourspace options including colourspace. * @returns Promise resolving to transformed image result. */ pipelineColourspace(fileId: string, options: PipelineColourspaceOptions): Promise>; /** * Converts colourspace of an image. * @param fileId Unique identifier of the image file to convert. * @param options ToColourspace options including target colourspace. * @returns Promise resolving to transformed image result. */ toColourspace(fileId: string, options: ToColourspaceOptions): Promise>; /** * Removes alpha channel from an image. * @param fileId Unique identifier of the image file to process. * @param options RemoveAlpha transformation options. * @returns Promise resolving to transformed image result. */ removeAlpha(fileId: string, options?: RemoveAlphaOptions): Promise>; /** * Ensures alpha channel exists in an image. * @param fileId Unique identifier of the image file to process. * @param options EnsureAlpha transformation options. * @returns Promise resolving to transformed image result. */ ensureAlpha(fileId: string, options?: EnsureAlphaOptions): Promise>; /** * Applies a custom transformation pipeline to an image. * @param fileId Unique identifier of the image file to transform. * @param steps Array of transformation steps to apply in sequence. * @returns Promise resolving to transformed image result. */ transform(fileId: string, steps: TransformationStep[]): Promise>; /** * Streams transform of a file (for large files, falls back to regular transform). * @param fileId Unique identifier of the image file to transform. * @param steps Array of transformation steps to apply in sequence. * @returns Promise resolving to stream with headers and size information. */ override transformStream(fileId: string, steps: TransformationStep[]): Promise<{ headers?: Record; size?: number; stream: Readable; }>; /** * Applies multiple transformations in sequence using Sharp. * @param buffer The original image buffer. * @param steps Array of transformation steps to apply. * @returns Promise resolving to transformed image buffer. * @private */ private applyTransformations; /** * Applies resize transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Resize transformation options. * @returns Modified Sharp instance with resize applied. * @private */ private applyResize; /** * Applies crop transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Crop transformation options. * @returns Modified Sharp instance with crop applied. * @private */ private applyCrop; /** * Applies rotate transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Rotate transformation options. * @returns Modified Sharp instance with rotation applied. * @private */ private applyRotate; /** * Applies sharpen transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Sharpen transformation options. * @returns Modified Sharp instance with sharpening applied. * @private */ private applySharpen; /** * Applies blur transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Blur transformation options. * @returns Modified Sharp instance with blurring applied. * @private */ private applyBlur; /** * Applies median filter using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Median transformation options. * @returns Modified Sharp instance with median filter applied. * @private */ private applyMedian; /** * Applies CLAHE (Contrast Limited Adaptive Histogram Equalization) using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options CLAHE transformation options. * @returns Modified Sharp instance with CLAHE applied. * @private */ private applyCLAHE; /** * Applies convolution using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Convolution transformation options. * @returns Modified Sharp instance with convolution applied. * @private */ private applyConvolve; /** * Applies threshold using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Threshold transformation options. * @returns Modified Sharp instance with thresholding applied. * @private */ private applyThreshold; /** * Applies boolean operation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Boolean operation options. * @returns Modified Sharp instance with boolean operation applied. * @private */ private applyBoolean; /** * Applies linear transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Linear transformation options. * @returns Modified Sharp instance with linear transformation applied. * @private */ private applyLinear; /** * Applies recombine transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Recombine transformation options. * @returns Modified Sharp instance with recombine applied. * @private */ private applyRecombine; /** * Applies modulate transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Modulate transformation options. * @returns Modified Sharp instance with modulation applied. * @private */ private applyModulate; /** * Applies tint using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Tint transformation options. * @returns Modified Sharp instance with tinting applied. * @private */ private applyTint; /** * Applies greyscale conversion using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Greyscale transformation options. * @returns Modified Sharp instance converted to greyscale. * @private */ private applyGreyscale; /** * Applies colourspace conversion using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Colourspace transformation options. * @returns Modified Sharp instance with colourspace conversion. * @private */ private applyColourspace; /** * Extracts channel using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Channel extraction options including channel index. * @returns Modified Sharp instance with channel extracted. * @private */ private applyExtractChannel; /** * Joins channels using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Channel joining options including image sources. * @returns Modified Sharp instance with channels joined. * @private */ private applyJoinChannel; /** * Applies band boolean operation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Band boolean options including operator. * @returns Modified Sharp instance with band boolean operation applied. * @private */ private applyBandbool; /** * Applies affine transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Affine transformation options including matrix. * @returns Modified Sharp instance with affine transformation applied. * @private */ private applyAffine; /** * Applies dilation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Dilate options including kernel size. * @returns Modified Sharp instance with dilation applied. * @private */ private applyDilate; /** * Applies erosion using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Erode options including kernel size. * @returns Modified Sharp instance with erosion applied. * @private */ private applyErode; /** * Applies pipeline colourspace using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Pipeline colourspace options including target colourspace. * @returns Modified Sharp instance with pipeline colourspace applied. * @private */ private applyPipelineColourspace; /** * Applies to colourspace conversion using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options To colourspace options including target colourspace. * @returns Modified Sharp instance with colourspace conversion applied. * @private */ private applyToColourspace; /** * Applies remove alpha using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Remove alpha transformation options. * @returns Modified Sharp instance with alpha channel removed. * @private */ private applyRemoveAlpha; /** * Applies ensure alpha using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Ensure alpha transformation options. * @returns Modified Sharp instance with alpha channel ensured. * @private */ private applyEnsureAlpha; /** * Applies format and quality transformation using Sharp. * @param sharpInstance The Sharp instance to modify. * @param options Format and quality transformation options. * @returns Modified Sharp instance with format and quality settings applied. * @private */ private applyFormatAndQuality; /** * Gets format-specific options for Sharp. * @param options Transform options containing format-specific settings. * @returns Record of format options for Sharp processing. * @private */ private getFormatOptions; /** * Validates that the file is a supported image. * @param file The file to validate. * @returns Promise that resolves if validation passes. * @throws Error if file size exceeds limits, wrong content type, unsupported format, or invalid image. * @private */ private validateImage; /** * Creates transformation result with metadata. * @param buffer The transformed image buffer. * @param originalFile The original file information. * @returns Image transformation result with metadata. * @private */ private createTransformResult; /** * Generates cache key for transformation. * @param fileId The file identifier. * @param steps Array of transformation steps. * @returns Unique cache key string. * @private */ private generateCacheKey; } export { ImageTransformer as default };