MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / generateMultipleFormats

Function generateMultipleFormats

scripts/optimize-images.js:107–136  ·  view source on GitHub ↗
(inputPath, filename)

Source from the content-addressed store, hash-verified

105
106// 生成多种格式 (with parallel processing)
107async function generateMultipleFormats(inputPath, filename) {
108 const baseName = path.parse(filename).name;
109
110 // Check file size threshold
111 const fileStats = await stat(inputPath);
112 if (fileStats.size < config.minFileSize) {
113 BuildLogger.log(`⏭️ 跳过小文件: ${filename} (${fileStats.size} bytes)`);
114 return [];
115 }
116
117 // Generate formats in parallel
118 const formatPromises = [];
119
120 // Generate JPEG version
121 const jpegPath = path.join(config.outputDir, `${baseName}.jpg`);
122 formatPromises.push(optimizeImage(inputPath, jpegPath, 'jpeg'));
123
124 // Generate WebP version
125 const webpPath = path.join(config.outputDir, `${baseName}.webp`);
126 formatPromises.push(optimizeImage(inputPath, webpPath, 'webp'));
127
128 // Generate PNG version (if original is PNG)
129 if (path.extname(filename).toLowerCase() === '.png') {
130 const pngPath = path.join(config.outputDir, `${baseName}.png`);
131 formatPromises.push(optimizeImage(inputPath, pngPath, 'png'));
132 }
133
134 const results = await Promise.all(formatPromises);
135 return results;
136}
137
138// 生成缩略图 (with better error recovery)
139async function generateThumbnails(inputPath, filename) {

Callers 1

processImagesInBatchesFunction · 0.85

Calls 2

optimizeImageFunction · 0.85
logMethod · 0.45

Tested by

no test coverage detected