import fs from "node:fs/promises"; import path from "node:path"; import sharp from "sharp"; const imageDir = path.resolve(import.meta.dirname, "../public/images/events"); const files = await fs.readdir(imageDir); for (const file of files.filter((name) => /\.jpe?g$/i.test(name))) { const sourcePath = path.join(imageDir, file); const baseName = path.basename(file, path.extname(file)); const jpeg = await fs.readFile(sourcePath); const { width, height } = await sharp(jpeg).metadata(); if (!width || !height) throw new Error(`Bildabmessungen fehlen: ${file}`); const avifPath = path.join(imageDir, `${baseName}.avif`); const svgPath = path.join(imageDir, `${baseName}.svg`); await sharp(jpeg).avif({ quality: 75 }).toFile(avifPath); const svg = `\n`; await fs.writeFile(svgPath, svg); console.log(`[images:events] ${file} → ${path.basename(avifPath)}, ${path.basename(svgPath)}`); }