/** * One-off image optimizer: converts the heavy marketing images to web-sized * WebP in public/images/opt/. Run with: node scripts/optimize-images.mjs */ import sharp from "sharp"; import { mkdir, stat, access } from "node:fs/promises"; import path from "node:path"; const SRC_DIR = "public/images"; const OUT_DIR = "public/images/opt"; const WIDTH = 1600; // plenty for card/section backgrounds const QUALITY = 72; const FILES = [ "HeroBanner1.jpg", "HeroBanner2.jpg", "HeroBanner3.jpg", "Pillar1.png", "Pillar2.png", "Pillar3.png", "Pillar4.png", "OurExperties.png", "OurExperties.jpg", ]; await mkdir(OUT_DIR, { recursive: true }); for (const file of FILES) { const src = path.join(SRC_DIR, file); const out = path.join(OUT_DIR, file.replace(/\.(jpe?g|png)$/i, ".webp")); // Skip sources that aren't uploaded yet. try { await access(src); } catch { console.log(`${file}: not found, skipped`); continue; } await sharp(src) .resize({ width: WIDTH, withoutEnlargement: true }) .webp({ quality: QUALITY }) .toFile(out); const before = (await stat(src)).size; const after = (await stat(out)).size; console.log( `${file}: ${(before / 1024 / 1024).toFixed(1)} MB → ${(after / 1024).toFixed(0)} KB` ); } console.log("done");