#!/usr/bin/env node // Builds a side-by-side of the original photo and the scene, for the fidelity check. Local, no API. // Usage: node scripts/compare.mjs --input original.jpg --scene scene.jpg --output compare.jpg // Needs the `sharp` package. Look at the result: shape, colour, label and logo must match. let sharp try { sharp = (await import('sharp')).default } catch { console.error('This script needs the sharp package. Run `npm install sharp` in the Skill folder (Node 20.9 or newer).') process.exit(1) } const usage = 'Usage: node scripts/compare.mjs --input original.jpg --scene scene.jpg --output compare.jpg' const allowed = new Set(['input', 'scene', 'output']) const options = {} const args = process.argv.slice(2) for (let index = 0; index < args.length; index += 1) { const key = args[index] if (!key.startsWith('--') || !allowed.has(key.slice(2))) { console.error(`Unknown argument: ${key}`) console.error(usage) process.exit(1) } const value = args[index + 1] if (value === undefined || value.startsWith('--')) { console.error(`${key} needs a value.`) console.error(usage) process.exit(1) } options[key.slice(2)] = value index += 1 } if (!options.input || !options.scene || !options.output) { console.error('Usage: node scripts/compare.mjs --input original.jpg --scene scene.jpg --output compare.jpg') process.exit(1) } const height = 1200 const [left, right] = await Promise.all([options.input, options.scene].map((file) => sharp(file).rotate().resize({ height }).jpeg({ quality: 90 }).toBuffer({ resolveWithObject: true }))) await sharp({ create: { width: left.info.width + right.info.width + 24, height, channels: 3, background: '#ffffff' } }) .composite([{ input: left.data, left: 0, top: 0 }, { input: right.data, left: left.info.width + 24, top: 0 }]) .jpeg({ quality: 90 }) .toFile(options.output) console.log(`${options.output}: original on the left, scene on the right`)