import sharp from 'sharp'; import path from 'path'; import fs from 'fs'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); async function convertNoImageToWebP() { const inputPath = path.join(__dirname, '../public/images/no-image.jpg'); const outputPath = path.join(__dirname, '../public/images/no-image.webp'); try { await sharp(inputPath) .resize(800, 600, { fit: 'cover', position: 'center' }) .webp({ quality: 65 }) .toFile(outputPath); console.log(`✅ 画像を変換しました: ${inputPath} -> ${outputPath}`); // ファイルサイズの比較 const originalSize = fs.statSync(inputPath).size; const newSize = fs.statSync(outputPath).size; const reduction = Math.round((1 - newSize / originalSize) * 100); console.log(`📊 ファイルサイズ: ${originalSize} bytes -> ${newSize} bytes (${reduction}% 削減)`); } catch (error) { console.error('❌ エラーが発生しました:', error); process.exit(1); } } convertNoImageToWebP();