#!/usr/bin/env node // One-off: generate after-otto-landscape.png from before-otto.jpg. // "Landscape oil style" is a legacy gallery example, not a catalog style, // so this script carries its own prompt rather than wiring it through // portraitPrompts.ts. 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'); process.exit(1); } const REFERENCE = path.resolve(ROOT, 'public/portraits/before-otto.jpg'); const OUT_PATH = path.resolve(ROOT, 'public/portraits/after-otto-landscape.png'); const refBytes = fs.readFileSync(REFERENCE); const refMime = 'image/jpeg'; const refB64 = refBytes.toString('base64'); const PROMPT = `Create a classical landscape oil-style portrait of the pet shown in the reference image — the look of a 19th-century Romantic-era oil painting on canvas, with the pet as the central subject in an autumn outdoor scene. Canvas requirements: - 1:1 square aspect ratio (equal width and height) - The artwork is a full-bleed oil painting on canvas — no border, no mat, no frame inside the image. The painted scene fills the entire canvas edge-to-edge. Subject: - Preserve the pet's identity exactly: breed, coat colour and pattern, markings, eye colour, fur length, and distinctive features must match the reference photo - Pose: pet sitting or standing in a confident 3/4 turn toward the viewer, head held high, alert, characterful Scene: - Place the pet in a romantic autumn landscape — golden-orange foliage, soft turning leaves on the ground, a hint of distant rolling hills or a meadow, warm low-angle late-afternoon sunlight - The scene composition keeps the pet as the unmistakable hero in the foreground, with the landscape behind in soft painterly falloff Style: - Classical oil-on-canvas aesthetic in the lineage of George Stubbs, John Emms, and 19th-century pet-portrait painters - Visible brushwork — soft confident strokes following fur direction and the contours of the leaves and ground - Layered glazes producing a warm Old-Master colour palette: burnt sienna, ochre, raw umber, cadmium yellow accents on the leaves, soft greens in the distance, warm flesh-tones on the pet's coat - Soft chiaroscuro lighting from a single warm light source — gentle shadow under the pet grounding it in the scene - Visible canvas-weave texture across the painted surface Composition and framing — strict: - The painted scene FILLS THE FULL CANVAS edge-to-edge. No empty white space, no border, no mat. - Position the pet's head and eyes in the upper-middle of the canvas (about 25–35% down from the top), with comfortable breathing room above filled with foliage / sky. - The pet's body fills the central composition; the landscape wraps around it. - Never crop the head, ears, eyes, muzzle, or nose. The mood should feel warm, romantic, classical, and gallery-ready — a Romantic-era oil pet portrait you'd find hanging in an old country house.`; const body = { contents: [ { parts: [ { text: PROMPT }, { inline_data: { mime_type: refMime, data: refB64 } }, ], }, ], generationConfig: { responseModalities: ['image', 'text'] }, }; const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image:generateContent`; console.log('→ generating after-otto-landscape.png (gemini-3-pro-image)'); 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(); console.error(`${r.status} ${r.statusText}: ${text.slice(0, 600)}`); process.exit(1); } const json = await r.json(); const parts = json?.candidates?.[0]?.content?.parts ?? []; let b64 = null; for (const part of parts) { const data = part?.inline_data?.data ?? part?.inlineData?.data; if (data) { b64 = data; break; } } if (!b64) { console.error('No image data in Gemini response'); process.exit(1); } fs.writeFileSync(OUT_PATH, Buffer.from(b64, 'base64')); console.log(`✓ ${path.relative(ROOT, OUT_PATH)}`);