UNPKG

@mvp-factory/holy-upload

Version:

File upload processing system extracted from Holy Habit project with security validation and image optimization

128 lines 3.83 kB
/** * Image Optimizer * * Optimizes images using Sharp library * Extracted from Holy Habit image processing logic */ import sharp from 'sharp'; import { ImageOptimizationOptions } from '../types/Upload'; export declare class ImageOptimizer { private static readonly DEFAULT_OPTIONS; /** * Optimize image file * * @param inputPath - Input file path * @param outputPath - Output file path (optional, defaults to input path) * @param options - Optimization options * @returns Optimization result */ static optimize(inputPath: string, outputPath?: string, options?: ImageOptimizationOptions): Promise<{ success: boolean; originalSize: number; optimizedSize: number; savings: number; }>; /** * Optimize image buffer * * @param buffer - Input image buffer * @param options - Optimization options * @returns Optimized buffer and metadata */ static optimizeBuffer(buffer: Buffer, options?: ImageOptimizationOptions): Promise<{ buffer: Buffer; metadata: sharp.OutputInfo; savings: number; }>; /** * Convert image to WebP format * * @param inputPath - Input file path * @param outputPath - Output file path * @param quality - WebP quality (1-100) * @returns Conversion result */ static convertToWebP(inputPath: string, outputPath: string, quality?: number): Promise<{ success: boolean; originalSize: number; webpSize: number; savings: number; }>; /** * Generate image thumbnails * * @param inputPath - Input file path * @param sizes - Array of thumbnail sizes * @param outputDir - Output directory * @returns Generated thumbnails */ static generateThumbnails(inputPath: string, sizes: { width: number; height: number; suffix: string; }[], outputDir: string): Promise<{ path: string; width: number; height: number; size: number; }[]>; /** * Get image metadata * * @param inputPath - Input file path * @returns Image metadata */ static getMetadata(inputPath: string): Promise<sharp.Metadata>; /** * Check if image needs resizing * * @param metadata - Image metadata * @param options - Optimization options * @returns True if resizing is needed */ private static needsResize; /** * Calculate optimal dimensions * * @param metadata - Image metadata * @param options - Optimization options * @returns Calculated dimensions */ private static calculateDimensions; /** * Create progressive JPEG * * @param inputPath - Input file path * @param outputPath - Output file path * @param quality - JPEG quality * @returns Processing result */ static createProgressiveJPEG(inputPath: string, outputPath: string, quality?: number): Promise<{ success: boolean; size: number; }>; /** * Remove EXIF data from image * * @param inputPath - Input file path * @param outputPath - Output file path * @returns Processing result */ static removeExifData(inputPath: string, outputPath: string): Promise<{ success: boolean; }>; /** * Batch optimize images in directory * * @param inputDir - Input directory * @param outputDir - Output directory * @param options - Optimization options * @returns Batch optimization results */ static batchOptimize(inputDir: string, outputDir: string, options?: ImageOptimizationOptions): Promise<{ processed: number; failed: number; totalSavings: number; }>; } //# sourceMappingURL=ImageOptimizer.d.ts.map