#!/usr/bin/env node // Generate fresh before-dog reference photos for the three new candidate // styles. Photoreal dog portraits rendered via Gemini Nano Banana, saved // as public/portraits/before-{name}.jpg so the existing pet-render // pipeline (which keys on `before-{name}.jpg`) can pick them up. // // Usage: // GEMINI_API_KEY=… node scripts/generate-before-dogs.mjs // // Env: // ONLY comma-separated dog ids to render (default: all) 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 OUT_DIR = path.resolve(ROOT, 'public/portraits'); const MODEL = 'gemini-3-pro-image'; // ─── Dog briefs ───────────────────────────────────────────────────── const DOGS = [ { id: 'banjo', prompt: `A photoreal hero portrait photograph of a Bearded Collie dog with a long, flowing, slightly tousled black-and-white double coat that frames the face in dramatic fringe. The dog faces the camera in a soft 3/4 turn, head held high and alert, ears flopped forward, gentle warm eyes catching the light. Three-quarter chest crop centred on the face — head and shoulders dominate the frame, lower body fades softly. Studio-soft natural daylight from a single window source, gentle reflected fill, clean catchlight in the eyes. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and muzzle, gentle falloff on the coat tips. Editorial pet photography, magazine-cover quality. Realistic skin and coat texture, individual hairs catchable in highlights, no painted or illustrated quality.`, }, { id: 'mochi', prompt: `A photoreal hero portrait photograph of a Bichon Frise puppy with a soft, fluffy, cloud-like pure-white curly coat, big round dark eyes, button-black nose, and small floppy ears partially hidden in the curls. The puppy faces the camera straight-on with a soft head tilt to one side, ears perked forward, expression curious and warm. Three-quarter chest crop — head and shoulders dominate the frame, the puppy looking up at the photographer. Soft natural daylight from a single window source, gentle warm fill, clean catchlights in both eyes. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and nose, soft falloff on the outer fluff. Editorial pet photography, magazine-cover quality. Realistic skin and coat texture, individual curls catchable in highlights, no painted or illustrated quality.`, }, { id: 'rex', prompt: `A photoreal full-body hero portrait photograph of a French Bulldog standing in a confident, regal pose — squared toward the camera in a slight 3/4 turn, head held high, ears upright and bat-shaped, chest forward, all four legs visible and planted firmly. The dog has a fawn-and-white coat with a black mask, dark expressive eyes, and a glossy black nose. Full standing body fills the vertical frame: head and ears anchored near the upper third, paws planted near the bottom edge. Soft natural daylight from a single window source, gentle reflected fill, clean catchlights in the eyes, soft contact shadow under the paws grounding the dog on a neutral floor. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the head and chest, gentle falloff on the back legs. Editorial pet photography, magazine-cover quality. Realistic skin and coat texture, no painted or illustrated quality.`, }, { id: 'murph', prompt: `A photoreal hero portrait photograph of a Pembroke Welsh Corgi with the classic red-and-white coat, large upright triangular ears, a foxy alert face, a black button nose, and warm dark brown eyes. The dog faces the camera in a soft 3/4 turn with head held high, ears perked forward, an open relaxed mouth showing a small pink tongue (a friendly half-smile, not a panting tongue-out look), eyes bright and confident. Three-quarter chest crop — head and shoulders dominate the frame, lower body fades softly. Studio-soft natural daylight from a single window source, gentle warm reflected fill, clean catchlights in both eyes. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and muzzle, gentle falloff on the coat tips. Editorial pet photography, magazine-cover quality. Realistic skin and coat texture, individual hairs catchable in highlights, no painted or illustrated quality, not cutesy or cartoonish.`, }, { id: 'frank', prompt: `A photoreal hero portrait photograph of an adult Long-Haired Dachshund with a deep mahogany red coat, long silky feathering on the ears, chest, and legs, an alert long muzzle with a glossy black nose, warm amber-brown eyes, and a slightly serious, characterful expression — NOT cutesy, NOT a puppy. The dog sits squarely facing the camera in a soft 3/4 turn, head held high, ears hanging down in graceful curtains, chest forward, front paws visible in a confident planted position. Three-quarter chest crop — head, ears, and front paws dominate the frame, lower body fades softly. Soft natural daylight from a single window source, gentle warm reflected fill, clean catchlights in the eyes. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and muzzle, gentle falloff on the coat tips. Editorial pet photography, magazine-cover quality. Realistic adult-dog skin and coat texture with individual hairs catchable in highlights, no painted or illustrated quality, no cartoon, no AI-cute aesthetic — the dog should look like a real adult adopted family dog photographed candidly.`, }, // ─── Cats (one per new style) ─────────────────────────────────────── { id: 'suki', prompt: `A photoreal hero portrait photograph of an adult tuxedo cat with a sharp, high-contrast black-and-white coat: glossy black back, ears, and tail, a snow-white chest and chin, white front paws, a clean white muzzle, and a black mask across the forehead. The cat has bright luminous green eyes with a clean catchlight and a glossy pink nose. Sitting upright in a confident 3/4 turn toward the camera, head held high, ears perked forward, alert and composed. Three-quarter chest crop — head and chest dominate the frame, lower body fades softly. Soft natural daylight from a single window source, gentle warm reflected fill. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and muzzle, gentle falloff on the coat. Editorial pet photography, magazine-cover quality. Realistic adult-cat fur texture with individual hairs catchable in highlights, no painted or illustrated quality, no cartoon, no AI-cute aesthetic.`, }, { id: 'marmalade', prompt: `A photoreal hero portrait photograph of an adult orange tabby cat with a warm classic ginger-and-cream coat showing distinct mackerel tabby stripes, a creamy white chest and chin, soft pink nose, and large round amber-gold eyes with a clean catchlight. The cat sits in a relaxed 3/4 turn toward the camera, head held high with a slight head tilt, ears perked forward, calm and characterful expression. Three-quarter chest crop — head and chest dominate the frame, lower body fades softly. Soft natural daylight from a single window source, gentle warm reflected fill. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the eyes and muzzle, gentle falloff on the coat tips. Editorial pet photography, magazine-cover quality. Realistic adult-cat fur texture with individual hairs catchable in highlights, no painted or illustrated quality, no cartoon, no AI-cute aesthetic — the cat should look like a real adult family cat photographed candidly.`, }, { id: 'iggy', prompt: `A photoreal full-body hero portrait photograph of an adult Sphynx cat (hairless breed) standing in a confident, regal pose — squared toward the camera in a slight 3/4 turn, head held high, large bat-like ears upright, chest forward, all four legs visible and planted firmly, long whip tail curled to one side. The cat has a soft warm-pink/peach skin tone with very subtle wrinkles around the shoulders and brow, a wedge-shaped face with high cheekbones, large lemon-yellow eyes with a clean catchlight, and a tiny pink nose. Full standing body fills the vertical frame: head and ears anchored near the upper third, paws planted near the bottom edge. Soft natural daylight from a single window source, gentle reflected fill, clean catchlights in the eyes, soft contact shadow under the paws grounding the cat on a neutral floor. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the head and chest, gentle falloff on the back legs. Editorial pet photography, magazine-cover quality. Realistic adult-cat skin texture, no painted or illustrated quality.`, }, // ─── Other animals (one per new style) ────────────────────────────── { id: 'chip', prompt: `A photoreal hero portrait photograph of an adult budgerigar (parakeet) perched on a simple wooden dowel — a vivid sky-blue body with crisp black scallop markings across the wings and head, a creamy-white face, bright violet cheek-patches, and large dark eyes with a small white catchlight. The bird is in a soft 3/4 turn toward the camera, head held high, beak closed, alert and characterful, feathers groomed and sleek. Three-quarter chest crop — head and chest dominate the frame, wings tucked. Soft natural daylight from a single window source, gentle reflected fill, clean catchlight in the eye. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text other than the simple wood perch. Sharp focus on the eye and beak, gentle falloff on the wing tips. Editorial pet photography, magazine-cover quality. Realistic adult-bird feather texture, no painted or illustrated quality, no cartoon, no AI-cute aesthetic.`, }, { id: 'popcorn', prompt: `A photoreal hero portrait photograph of an adult Abyssinian guinea pig with a classic agouti rosette coat — multiple swirling rosettes of warm caramel, cream, and dark chocolate fur radiating from the body, a stubby pink nose, small alert dark eyes with a clean catchlight, and tiny round ears partially hidden in the fur whorls. The guinea pig sits squarely on a soft neutral surface facing the camera in a slight 3/4 turn, head held high and alert, an expression of curious calm. Three-quarter body crop — head and chest dominate the frame, hindquarters fade softly. Soft natural daylight from a single window source, gentle warm reflected fill, clean catchlights in both eyes. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the face and eyes, gentle falloff on the fur tips. Editorial pet photography, magazine-cover quality. Realistic adult-guinea-pig fur texture with individual hairs catchable in highlights, no painted or illustrated quality, no cartoon, no AI-cute aesthetic.`, }, { id: 'capy', prompt: `A photoreal full-body hero portrait photograph of an adult capybara standing in a confident, regal pose on a neutral floor — squared toward the camera in a slight 3/4 turn, head held high, small rounded ears upright, chest forward, all four blocky legs visible and planted firmly, body fully upright. The capybara has dense coarse cinnamon-brown fur, a long blunt muzzle with a wide pink-grey nose, small dark eyes with a clean catchlight, and a calm, almost philosophical expression. Full standing body fills the vertical frame: head and ears anchored near the upper third, paws planted near the bottom edge. Soft natural daylight from a single window source, gentle reflected fill, clean catchlights in the eyes, soft contact shadow under the paws grounding the animal on a neutral floor. Background is a quiet, slightly out-of-focus soft cream / oat backdrop with very gentle vignetting — no scenery, no props, no text. Sharp focus on the head and chest, gentle falloff on the back legs. Editorial pet photography, magazine-cover quality. Realistic adult-capybara coarse-fur texture, no painted or illustrated quality.`, }, ]; const ONLY = process.env.ONLY ? new Set(process.env.ONLY.split(',').map((s) => s.trim())) : null; async function renderViaGemini(prompt, outPath) { const body = { contents: [{ parts: [{ text: prompt }] }], generationConfig: { responseModalities: ['image', 'text'] }, }; const url = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent`; 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, 400)}`); } 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) throw new Error('No image data in Gemini response'); fs.writeFileSync(outPath, Buffer.from(b64, 'base64')); } async function renderDog(dog) { const outPath = path.join(OUT_DIR, `before-${dog.id}.jpg`); console.log(`→ ${dog.id.padEnd(8)} → ${path.relative(ROOT, outPath)}`); // Gemini returns PNG; we write the bytes verbatim — extension is cosmetic // (Node Image/Next don't care, and the existing before-*.jpg files mix // formats too). If we wanted strict JPEG we'd run through sharp. await renderViaGemini(dog.prompt, outPath); console.log(` ✓ saved`); } const targets = ONLY ? DOGS.filter((d) => ONLY.has(d.id)) : DOGS; console.log(`Model: ${MODEL}`); console.log(`Out: ${path.relative(ROOT, OUT_DIR)}`); console.log(`Dogs: ${targets.map((d) => d.id).join(', ')}\n`); const results = await Promise.allSettled(targets.map(renderDog)); let fails = 0; results.forEach((r, i) => { if (r.status === 'rejected') { fails++; console.error(` ✗ ${targets[i].id}: ${r.reason?.message || r.reason}`); } }); console.log(`\nDone. ${results.length - fails}/${results.length} succeeded.`);