noupload 1.0.1 → 1.0.3

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,46 @@
1
+ import { writeFileSync } from 'node:fs';
2
+ import { extname } from 'node:path';
3
+
4
+ /**
5
+ * Get MIME type from file extension
6
+ */
7
+ export function getMimeType(filePath: string): string {
8
+ const ext = extname(filePath).toLowerCase().slice(1);
9
+ const mimeMap: Record<string, string> = {
10
+ jpg: 'image/jpeg',
11
+ jpeg: 'image/jpeg',
12
+ png: 'image/png',
13
+ gif: 'image/gif',
14
+ bmp: 'image/bmp',
15
+ tiff: 'image/tiff',
16
+ tif: 'image/tiff',
17
+ };
18
+ return mimeMap[ext] || 'image/png';
19
+ }
20
+
21
+ /**
22
+ * Write a Jimp image to a file with proper MIME type detection
23
+ */
24
+ export async function writeImage(
25
+ // biome-ignore lint/suspicious/noExplicitAny: Jimp types are overly complex
26
+ image: any,
27
+ outputPath: string,
28
+ options?: { quality?: number }
29
+ ): Promise<void> {
30
+ const mime = getMimeType(outputPath);
31
+
32
+ let buffer: Buffer;
33
+
34
+ if (mime === 'image/jpeg' && options?.quality) {
35
+ buffer = await image.getBuffer(mime, { quality: options.quality });
36
+ } else {
37
+ buffer = await image.getBuffer(mime);
38
+ }
39
+
40
+ writeFileSync(outputPath, buffer);
41
+ }
42
+
43
+ /**
44
+ * Supported image formats for Jimp
45
+ */
46
+ export const SUPPORTED_FORMATS = ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'tiff'];