const sharp = require('sharp') as typeof import('sharp').default; // PDFKit and the Word image renderer accept JPEG/PNG. The source bytes and // their recorded SHA-256 remain untouched; WebP is only converted for display. export async function renderableInspectionImage(source: Buffer): Promise { const isWebp = source.length >= 12 && source.subarray(0, 4).toString('ascii') === 'RIFF' && source.subarray(8, 12).toString('ascii') === 'WEBP'; if (!isWebp) return source; return sharp(source) .resize({ width: 1600, height: 1200, fit: 'inside', withoutEnlargement: true }) .png() .toBuffer(); }