#!/usr/bin/env node // One-off: create a NEW dog (Hugo, a Hungarian Vizsla) and render the // catalog example for the Landscape style. // // Step 1 before-hugo.jpg — a candid "phone snap" reference // photo (text-to-image), the kind // a customer would upload. // Step 2 after-hugo-landscape-oil.png — that dog rendered through the // canonical LANDSCAPE_OIL prompt // (image-to-image), the catalog tile. // // Both steps run on gemini-3-pro-image (Nano Banana Pro) — it // renders the classical-oil landscape noticeably richer than gpt-image-2, // and matches the other painterly catalog tiles. Output is left at the // model's default (~1024²), matching every other after-*.png tile. // // The Landscape prompt is read straight out of app/data/portraitPrompts.ts // so the example always reflects the live style definition. // // Usage: GEMINI_API_KEY in .env.local (auto-loaded), then: // node scripts/generate-hugo-landscape.mjs import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.resolve(__dirname, '..'); function loadEnvLocal() { const p = path.join(ROOT, '.env.local'); if (!fs.existsSync(p)) return; for (const raw of fs.readFileSync(p, 'utf8').split('\n')) { const line = raw.trim(); if (!line || line.startsWith('#')) continue; const eq = line.indexOf('='); if (eq < 0) continue; const key = line.slice(0, eq).trim(); let val = line.slice(eq + 1).trim(); if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) { val = val.slice(1, -1); } if (!(key in process.env)) process.env[key] = val; } } loadEnvLocal(); const GEMINI_KEY = process.env.GEMINI_API_KEY; if (!GEMINI_KEY) { console.error('GEMINI_API_KEY not set (looked in env + .env.local)'); process.exit(1); } const MODEL = 'gemini-3-pro-image'; const PORTRAITS = path.resolve(ROOT, 'public/portraits'); const BEFORE_PATH = path.join(PORTRAITS, 'before-hugo.jpg'); const AFTER_PATH = path.join(PORTRAITS, 'after-hugo-landscape-oil.png'); // New dog: Hugo, a Hungarian Vizsla — warm rust coat that glows in the // classical autumn-landscape palette. const BEFORE_PROMPT = `A natural, candid pet photograph — the kind a customer would casually snap with their phone. ` + `Composition: head-and-shoulders to bust crop, the subject occupying roughly the centre 60-75% of a square frame with comfortable margin on all four sides. ` + `Subject: a Hungarian Vizsla dog sitting calmly outdoors, sleek short golden-rust coat, long velvety drop ears, soft amber eyes looking directly at the camera, gentle alert expression, a little wet nose, warm late-afternoon golden-hour light, blurred green lawn and a few trees softly out of focus behind. ` + `Style: realistic photographic quality, soft natural light, narrow depth of field, slight grain, no text, no watermark, no studio lighting, no people, no other animals. ` + `Aspect ratio: square (1:1).`; // Pull the live LANDSCAPE_OIL prompt out of the TS module as plain text // (no TS runtime needed) so this example tracks the real style definition. function extractConst(name) { const ts = fs.readFileSync(path.join(ROOT, 'app/data/portraitPrompts.ts'), 'utf8'); const m = ts.match(new RegExp('const ' + name + ' = `([\\s\\S]*?)`;', 'm')); if (!m) throw new Error('Could not find prompt const: ' + name); return m[1]; } function pickImageB64(json) { const parts = json?.candidates?.[0]?.content?.parts ?? []; for (const part of parts) { const data = part?.inline_data?.data ?? part?.inlineData?.data; if (data) return data; } return null; } async function gemini(parts, label) { const body = { contents: [{ parts }], generationConfig: { responseModalities: ['image', 'text'] }, }; const url = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent`; console.log(`→ ${label} (${MODEL})`); const r = await fetch(url, { method: 'POST', headers: { 'x-goog-api-key': GEMINI_KEY, 'content-type': 'application/json' }, body: JSON.stringify(body), }); if (!r.ok) { const text = await r.text(); throw new Error(`${r.status} ${r.statusText}: ${text.slice(0, 600)}`); } const b64 = pickImageB64(await r.json()); if (!b64) throw new Error('No image data in Gemini response'); return Buffer.from(b64, 'base64'); } // Sniff the real container so the reference mime is honest regardless of // the .jpg extension. function mimeOf(buf) { if (buf[0] === 0x89 && buf[1] === 0x50) return 'image/png'; return 'image/jpeg'; } // ─── Step 1: the new dog's reference photo ────────────────────────── const beforeBuf = await gemini([{ text: BEFORE_PROMPT }], 'before-hugo.jpg — candid Vizsla reference'); fs.writeFileSync(BEFORE_PATH, beforeBuf); console.log(` ✓ ${path.relative(ROOT, BEFORE_PATH)} (${beforeBuf.length.toLocaleString()} bytes)`); // ─── Step 2: the Landscape-style catalog example ──────────────────── const LANDSCAPE_OIL = extractConst('LANDSCAPE_OIL'); const afterBuf = await gemini( [ { text: LANDSCAPE_OIL }, { inline_data: { mime_type: mimeOf(beforeBuf), data: beforeBuf.toString('base64') } }, ], 'after-hugo-landscape-oil.png — Landscape style render', ); fs.writeFileSync(AFTER_PATH, afterBuf); console.log(` ✓ ${path.relative(ROOT, AFTER_PATH)} (${afterBuf.length.toLocaleString()} bytes)`); console.log('\nDone.');