Branchwell

Lumen & Gesso / website · lumengesso.com / scripts / generate-before-dogs.mjs

1#!/usr/bin/env node
2// Generate fresh before-dog reference photos for the three new candidate
3// styles. Photoreal dog portraits rendered via Gemini Nano Banana, saved
4// as public/portraits/before-{name}.jpg so the existing pet-render
5// pipeline (which keys on `before-{name}.jpg`) can pick them up.
6//
7// Usage:
8// GEMINI_API_KEY=… node scripts/generate-before-dogs.mjs
9//
10// Env:
11// ONLY comma-separated dog ids to render (default: all)
12
13import fs from 'node:fs';
14import path from 'node:path';
15import { fileURLToPath } from 'node:url';
16
17const __dirname = path.dirname(fileURLToPath(import.meta.url));
18const ROOT = path.resolve(__dirname, '..');
19
20function loadEnvLocal() {
21 const p = path.join(ROOT, '.env.local');
22 if (!fs.existsSync(p)) return;
23 for (const raw of fs.readFileSync(p, 'utf8').split('\n')) {
24 const line = raw.trim();
25 if (!line || line.startsWith('#')) continue;
26 const eq = line.indexOf('=');
27 if (eq < 0) continue;
28 const key = line.slice(0, eq).trim();
29 let val = line.slice(eq + 1).trim();
30 if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
31 val = val.slice(1, -1);
32 }
33 if (!(key in process.env)) process.env[key] = val;
34 }
35}
36loadEnvLocal();
37
38const GEMINI_KEY = process.env.GEMINI_API_KEY;
39if (!GEMINI_KEY) {
40 console.error('GEMINI_API_KEY not set');
41 process.exit(1);
42}
43
44const OUT_DIR = path.resolve(ROOT, 'public/portraits');
45const MODEL = 'gemini-3-pro-image';
46
47// ─── Dog briefs ─────────────────────────────────────────────────────
48const DOGS = [
49 {
50 id: 'banjo',
51 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.`,
52 },
53 {
54 id: 'mochi',
55 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.`,
56 },
57 {
58 id: 'rex',
59 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.`,
60 },
61 {
62 id: 'murph',
63 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.`,
64 },
65 {
66 id: 'frank',
67 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.`,
68 },
69 // ─── Cats (one per new style) ───────────────────────────────────────
70 {
71 id: 'suki',
72 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.`,
73 },
74 {
75 id: 'marmalade',
76 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.`,
77 },
78 {
79 id: 'iggy',
80 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.`,
81 },
82 // ─── Other animals (one per new style) ──────────────────────────────
83 {
84 id: 'chip',
85 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.`,
86 },
87 {
88 id: 'popcorn',
89 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.`,
90 },
91 {
92 id: 'capy',
93 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.`,
94 },
95];
96
97const ONLY = process.env.ONLY ? new Set(process.env.ONLY.split(',').map((s) => s.trim())) : null;
98
99async function renderViaGemini(prompt, outPath) {
100 const body = {
101 contents: [{ parts: [{ text: prompt }] }],
102 generationConfig: { responseModalities: ['image', 'text'] },
103 };
104 const url = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent`;
105 const r = await fetch(url, {
106 method: 'POST',
107 headers: { 'x-goog-api-key': GEMINI_KEY, 'content-type': 'application/json' },
108 body: JSON.stringify(body),
109 });
110 if (!r.ok) {
111 const text = await r.text();
112 throw new Error(`${r.status} ${r.statusText}: ${text.slice(0, 400)}`);
113 }
114 const json = await r.json();
115 const parts = json?.candidates?.[0]?.content?.parts ?? [];
116 let b64 = null;
117 for (const part of parts) {
118 const data = part?.inline_data?.data ?? part?.inlineData?.data;
119 if (data) { b64 = data; break; }
120 }
121 if (!b64) throw new Error('No image data in Gemini response');
122 fs.writeFileSync(outPath, Buffer.from(b64, 'base64'));
123}
124
125async function renderDog(dog) {
126 const outPath = path.join(OUT_DIR, `before-${dog.id}.jpg`);
127 console.log(`→ ${dog.id.padEnd(8)} → ${path.relative(ROOT, outPath)}`);
128 // Gemini returns PNG; we write the bytes verbatim — extension is cosmetic
129 // (Node Image/Next don't care, and the existing before-*.jpg files mix
130 // formats too). If we wanted strict JPEG we'd run through sharp.
131 await renderViaGemini(dog.prompt, outPath);
132 console.log(` ✓ saved`);
133}
134
135const targets = ONLY ? DOGS.filter((d) => ONLY.has(d.id)) : DOGS;
136console.log(`Model: ${MODEL}`);
137console.log(`Out: ${path.relative(ROOT, OUT_DIR)}`);
138console.log(`Dogs: ${targets.map((d) => d.id).join(', ')}\n`);
139
140const results = await Promise.allSettled(targets.map(renderDog));
141let fails = 0;
142results.forEach((r, i) => {
143 if (r.status === 'rejected') {
144 fails++;
145 console.error(` ✗ ${targets[i].id}: ${r.reason?.message || r.reason}`);
146 }
147});
148console.log(`\nDone. ${results.length - fails}/${results.length} succeeded.`);