@happyvertical/images 0.74.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,218 @@
1
+ import { ConvertOptions, GetImageProcessorOptions, HashAlgorithm, ImageDimensions, ImageInput, ImageMetadata, ResizeOptions, ThumbnailOptions } from './shared/types.js';
2
+ /**
3
+ * @happyvertical/images - Image processing utilities with adapter pattern
4
+ *
5
+ * Provides a unified interface for image processing that scales from
6
+ * static sites to enterprise deployments:
7
+ *
8
+ * - **Sharp adapter**: Fast native processing (default)
9
+ * - **Jimp adapter**: Pure JavaScript fallback (serverless/edge)
10
+ * - **imgproxy adapter**: Self-hosted remote processing (scale)
11
+ *
12
+ * @example Basic usage with auto-detection
13
+ * ```typescript
14
+ * import { getDimensions, generateThumbnail } from '@happyvertical/images';
15
+ *
16
+ * // Automatically uses Sharp if available, falls back to Jimp
17
+ * const dims = await getDimensions('/path/to/image.jpg');
18
+ * await generateThumbnail('/path/to/image.jpg', '/path/to/thumb.jpg', {
19
+ * maxWidth: 300,
20
+ * maxHeight: 300
21
+ * });
22
+ * ```
23
+ *
24
+ * @example Using factory directly
25
+ * ```typescript
26
+ * import { getImageProcessor } from '@happyvertical/images';
27
+ *
28
+ * const processor = await getImageProcessor({ type: 'sharp' });
29
+ * const metadata = await processor.getMetadata('/path/to/image.jpg');
30
+ * ```
31
+ *
32
+ * @example Using imgproxy for remote processing
33
+ * ```typescript
34
+ * import { getImageProcessor } from '@happyvertical/images';
35
+ *
36
+ * const processor = await getImageProcessor({
37
+ * type: 'imgproxy',
38
+ * baseUrl: 'https://imgproxy.example.com',
39
+ * key: 'signing-key',
40
+ * salt: 'signing-salt'
41
+ * });
42
+ * ```
43
+ *
44
+ * @packageDocumentation
45
+ */
46
+ export { ImgproxyAdapter, type SignedUrlOptions, signImgproxyUrl, } from './adapters/imgproxy.js';
47
+ export { JimpAdapter } from './adapters/jimp.js';
48
+ export { SharpAdapter } from './adapters/sharp.js';
49
+ export { generateHeadlineCard, type HeadlineCardOptions, type HeadlineCardResult, type HeadlineCardTemplate, resetFontCache, } from './headline-card.js';
50
+ export * from './shared/errors.js';
51
+ export { getAvailableAdapters, getImageProcessor } from './shared/factory.js';
52
+ export * from './shared/types.js';
53
+ /**
54
+ * Reset the cached processor (useful for testing)
55
+ */
56
+ export declare function resetProcessor(): void;
57
+ /**
58
+ * Get image dimensions
59
+ *
60
+ * Uses auto-detection to select the best available processor.
61
+ *
62
+ * @param input - Image path or Buffer
63
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
64
+ * @returns Promise resolving to image dimensions
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * import { getDimensions } from '@happyvertical/images';
69
+ *
70
+ * // Auto-detect adapter
71
+ * const dims = await getDimensions('/path/to/image.jpg');
72
+ * console.log(`${dims.width}x${dims.height}`);
73
+ *
74
+ * // Force specific adapter
75
+ * const jimp = await getDimensions(buffer, { type: 'jimp' });
76
+ * ```
77
+ */
78
+ export declare function getDimensions(input: ImageInput, adapterOptions?: GetImageProcessorOptions): Promise<ImageDimensions>;
79
+ /**
80
+ * Generate a thumbnail image
81
+ *
82
+ * Creates a smaller version of the image while maintaining aspect ratio.
83
+ * Uses auto-detection to select the best available processor.
84
+ *
85
+ * @param input - Source image path or Buffer
86
+ * @param output - Output file path
87
+ * @param options - Thumbnail options (maxWidth, maxHeight, quality, format)
88
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * import { generateThumbnail } from '@happyvertical/images';
93
+ *
94
+ * // Create 300x300 max thumbnail
95
+ * await generateThumbnail('/path/to/image.jpg', '/path/to/thumb.jpg', {
96
+ * maxWidth: 300,
97
+ * maxHeight: 300,
98
+ * quality: 85
99
+ * });
100
+ *
101
+ * // Convert to WebP while thumbnailing
102
+ * await generateThumbnail('/path/to/image.jpg', '/path/to/thumb.webp', {
103
+ * maxWidth: 200,
104
+ * format: 'webp'
105
+ * });
106
+ * ```
107
+ */
108
+ export declare function generateThumbnail(input: ImageInput, output: string, options?: ThumbnailOptions, adapterOptions?: GetImageProcessorOptions): Promise<void>;
109
+ /**
110
+ * Convert image format
111
+ *
112
+ * Converts an image to a different format with optional quality settings.
113
+ * Uses auto-detection to select the best available processor.
114
+ *
115
+ * @param input - Source image path or Buffer
116
+ * @param output - Output file path (format inferred from extension)
117
+ * @param options - Conversion options (format, quality)
118
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import { convertFormat } from '@happyvertical/images';
123
+ *
124
+ * // Convert PNG to JPEG
125
+ * await convertFormat('/path/to/image.png', '/path/to/image.jpg', {
126
+ * quality: 90
127
+ * });
128
+ *
129
+ * // Convert to WebP with explicit format
130
+ * await convertFormat('/path/to/image.jpg', '/path/to/image.webp', {
131
+ * format: 'webp',
132
+ * quality: 80
133
+ * });
134
+ * ```
135
+ */
136
+ export declare function convertFormat(input: ImageInput, output: string, options?: ConvertOptions, adapterOptions?: GetImageProcessorOptions): Promise<void>;
137
+ /**
138
+ * Get image metadata
139
+ *
140
+ * Extracts comprehensive metadata including dimensions, format, color space,
141
+ * and optionally EXIF/IPTC/XMP data.
142
+ * Uses auto-detection to select the best available processor.
143
+ *
144
+ * @param input - Image path or Buffer
145
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
146
+ * @returns Promise resolving to metadata object
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * import { getImageMetadata } from '@happyvertical/images';
151
+ *
152
+ * const metadata = await getImageMetadata('/path/to/photo.jpg');
153
+ * console.log(`Format: ${metadata.format}`);
154
+ * console.log(`Dimensions: ${metadata.width}x${metadata.height}`);
155
+ * console.log(`Has alpha: ${metadata.hasAlpha}`);
156
+ * if (metadata.exif) {
157
+ * console.log('EXIF data:', metadata.exif);
158
+ * }
159
+ * ```
160
+ */
161
+ export declare function getImageMetadata(input: ImageInput, adapterOptions?: GetImageProcessorOptions): Promise<ImageMetadata>;
162
+ /**
163
+ * Compute image hash
164
+ *
165
+ * Generates a hash of the image for deduplication or comparison.
166
+ * Uses auto-detection to select the best available processor.
167
+ *
168
+ * @param input - Image path or Buffer
169
+ * @param algorithm - Hash algorithm: 'perceptual' (default), 'md5', 'sha256'
170
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
171
+ * @returns Promise resolving to hash string
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * import { getImageHash } from '@happyvertical/images';
176
+ *
177
+ * // Perceptual hash for finding similar images
178
+ * const pHash = await getImageHash('/path/to/image.jpg');
179
+ * console.log(`Perceptual hash: ${pHash}`);
180
+ *
181
+ * // Cryptographic hash for exact matching
182
+ * const sha256 = await getImageHash('/path/to/image.jpg', 'sha256');
183
+ * console.log(`SHA-256: ${sha256}`);
184
+ * ```
185
+ */
186
+ export declare function getImageHash(input: ImageInput, algorithm?: HashAlgorithm, adapterOptions?: GetImageProcessorOptions): Promise<string>;
187
+ /**
188
+ * Resize image with full control
189
+ *
190
+ * Resizes an image to specific dimensions with control over fit mode.
191
+ * Uses auto-detection to select the best available processor.
192
+ *
193
+ * @param input - Source image path or Buffer
194
+ * @param output - Output file path
195
+ * @param options - Resize options (width, height, fit, quality, format)
196
+ * @param adapterOptions - Optional adapter configuration to override auto-detection
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * import { resizeImage } from '@happyvertical/images';
201
+ *
202
+ * // Resize to exact dimensions (may crop)
203
+ * await resizeImage('/path/to/image.jpg', '/path/to/resized.jpg', {
204
+ * width: 800,
205
+ * height: 600,
206
+ * fit: 'cover' // Crop to fill
207
+ * });
208
+ *
209
+ * // Resize to fit within dimensions (no crop)
210
+ * await resizeImage('/path/to/image.jpg', '/path/to/resized.jpg', {
211
+ * width: 800,
212
+ * height: 600,
213
+ * fit: 'inside' // Fit within, may be smaller
214
+ * });
215
+ * ```
216
+ */
217
+ export declare function resizeImage(input: ImageInput, output: string, options: ResizeOptions, adapterOptions?: GetImageProcessorOptions): Promise<void>;
218
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