import { FileEntity } from '../interfaces/file-entity.interface'; import { IFileProcessor } from '../interfaces/file-processor.interface'; import { ProcessOptions, ProcessResult } from '../interfaces/processor-options.interface'; /** * 图片处理器配置 */ export interface ImageProcessorOptions { /** 裁剪选项 */ crop?: { /** 宽度 */ width: number; /** 高度 */ height: number; /** 裁剪位置 */ position?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; /** 是否保持比例 */ fit?: 'cover' | 'contain' | 'fill' | 'inside' | 'outside'; }; /** 缩放选项 */ resize?: { /** 宽度或百分比 */ width?: number; /** 高度或百分比 */ height?: number; /** 是否保持宽高比 */ keepAspect?: boolean; /** 放大算法 */ enlarger?: 'nearest' | 'bilinear' | 'bicubic' | 'no'; /** 缩小算法 */ reducer?: 'nearest' | 'bilinear' | 'bicubic'; }; /** 压缩选项 */ compress?: { /** 质量 (0-100) */ quality?: number; /** 输出格式 */ format?: 'jpeg' | 'png' | 'webp' | 'avif' | 'tiff' | 'gif'; /** 渐进式JPEG */ progressive?: boolean; /** 优化 */ optimize?: boolean; }; /** 滤镜效果 */ filters?: { /** 模糊 */ blur?: number; /** 锐化 */ sharpen?: boolean | number; /** 亮度调整 (-100 到 100) */ brightness?: number; /** 对比度调整 (-100 到 100) */ contrast?: number; /** 饱和度调整 (-100 到 100) */ saturation?: number; /** 伽马值 */ gamma?: number; /** 旋转角度 */ rotate?: number; /** 翻转 */ flip?: boolean; /** 水平翻转 */ flop?: boolean; }; /** 水印选项 */ watermark?: { /** 水印图片路径 */ image?: string; /** 水印文字 */ text?: string; /** 位置 */ position?: 'center' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; /** 透明度 (0-1) */ opacity?: number; /** 缩放比例 */ scale?: number; /** 文字选项 */ textOptions?: { /** 字体大小 */ size?: number; /** 字体颜色 */ color?: string; /** 字体 */ font?: string; /** 背景色 */ background?: string; }; }; /** 缩略图生成 */ thumbnails?: Array<{ /** 名称/标识 */ name: string; /** 宽度 */ width: number; /** 高度 */ height: number; /** 裁剪选项 */ fit?: 'cover' | 'contain' | 'fill'; /** 质量覆盖 */ quality?: number; }>; /** 输出选项 */ output?: { /** 是否保留原始文件 */ keepOriginal?: boolean; /** 输出目录 */ directory?: string; /** 文件名后缀 */ suffix?: string; /** 是否覆盖已存在文件 */ overwrite?: boolean; }; } /** 图片处理结果 */ export interface ImageProcessResult { /** 处理状态 */ status: 'success' | 'partial' | 'failed'; /** 原始图片信息 */ original: { width: number; height: number; format: string; size: number; hasAlpha: boolean; channels: number; }; /** 处理后的图片信息 */ processed?: { width: number; height: number; format: string; size: number; path?: string; url?: string; }; /** 缩略图列表 */ thumbnails?: Array<{ name: string; width: number; height: number; size: number; path?: string; url?: string; }>; /** 压缩率 */ compressionRatio?: number; /** 处理耗时(毫秒) */ duration: number; /** 错误信息 */ error?: string; } export declare class ImageProcessor implements IFileProcessor { readonly name = "image"; readonly supportedTypes: string[]; private readonly logger; validate(buffer: Buffer): Promise; process(file: FileEntity, options: ProcessOptions & { imageOptions?: ImageProcessorOptions; }): Promise; /** * 获取文件缓冲区 */ private getFileBuffer; /** * 应用滤镜 */ private applyFilters; /** * 应用裁剪 */ private applyCrop; /** * 应用缩放 */ private applyResize; /** * 应用压缩 */ private applyCompression; /** * 应用水印 */ private applyWatermark; /** * 创建文字水印SVG */ private createTextWatermark; /** * 获取Gravity常量 */ private getGravity; /** * 生成缩略图 */ private generateThumbnail; } /** * 图片处理装饰器 */ export declare function ImageProcess(options: ImageProcessorOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;