#!/usr/bin/env node // Generate raw "phone-snap" pet reference photos via Nano Banana. // Output mimics what a customer would upload: natural lighting, real // settings, no studio gloss. These become the REFERENCE input for // generate-style-examples.mjs. // // Usage: // GEMINI_API_KEY=AIza... node scripts/generate-pet-photo.mjs // // Optional: // ONLY=owl,goat restrict to specific jobs by id 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, '..'); const GEMINI_KEY = process.env.GEMINI_API_KEY; if (!GEMINI_KEY) { console.error('GEMINI_API_KEY is not set.'); process.exit(1); } const MODEL = 'gemini-3-pro-image'; const PORTRAITS_DIR = path.join(ROOT, 'public/portraits'); const ONLY = process.env.ONLY ? new Set(process.env.ONLY.split(',').map((s) => s.trim())) : null; // Each job describes one pet — fed straight into a photo-realism prompt. // `out` is what the file is named under /public/portraits/. The subject // description should read like a real-life caption, with concrete // details (breed, coat, pose, setting, light) so the model commits to a // believable still rather than a generic stock-art rendering. const JOBS = [ { id: 'owl', out: 'before-owl.jpg', subject: 'a tawny barn owl perched on a rough-hewn wooden beam, head turned slightly toward camera, alert amber eyes, soft feather detail, dim golden sunset light streaming through an open hayloft window behind it', }, { id: 'goat', out: 'before-goat.jpg', subject: 'a Nigerian Dwarf goat with chestnut-and-white markings standing on a grassy pasture, head tilted curiously toward the camera, soft floppy ears, late-afternoon golden-hour light, distant fence and rolling hills out of focus behind', }, { id: 'ferret', out: 'before-ferret.jpg', subject: 'a sable-mask ferret lying relaxed on a cream linen blanket, looking up directly at the camera, small dark eyes bright, soft window light catching the silvery fur, a small wooden bookshelf softly out of focus behind', }, { id: 'fox', out: 'before-fox.jpg', subject: 'a young red fox sitting alert on a moss-covered forest floor, looking forward toward the camera, ears perked, fluffy white-tipped tail tucked around feet, soft dappled morning light filtering through trees', }, // ─── Testimonial dogs (homepage review carousel) ────────────────── { id: 'tucker', out: 'before-tucker.jpg', subject: 'a fluffy golden retriever puppy sitting on a sunlit wooden porch step, head tilted slightly toward the camera, soft amber eyes and a little wet nose, warm late-afternoon light, a few potted plants softly out of focus behind', }, { id: 'willow', out: 'before-willow.jpg', subject: 'a black-and-white border collie lying on a worn living-room rug, chin resting on her paws, looking up directly at the camera with bright attentive eyes, soft window light, a couch edge and a leafy houseplant out of focus behind', }, { id: 'gus', out: 'before-gus.jpg', subject: 'a Pembroke Welsh corgi sitting on a kitchen floor, big ears perked up, tongue out in a happy open-mouth grin, looking toward the camera, soft daylight from a nearby window, pale cabinets softly out of focus behind', }, { id: 'nova', out: 'before-nova.jpg', subject: 'a Bernese mountain dog resting on a back-yard deck, head turned toward the camera, calm dark eyes, glossy tricolor coat, soft overcast daylight, a wooden railing and green shrubs out of focus behind', }, { id: 'waffle', out: 'before-waffle.jpg', subject: 'a smooth-coat dachshund standing on a tufted armchair, looking alertly toward the camera, long body and soft floppy ears, warm lamp light from the side, a cozy living-room wall softly out of focus behind', }, ]; async function generate(job) { const outPath = path.join(PORTRAITS_DIR, job.out); const 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: ${job.subject}. ` + `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).`; 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')); console.log(` ✓ ${path.relative(ROOT, outPath)}`); } const targets = ONLY ? JOBS.filter((j) => ONLY.has(j.id)) : JOBS; console.log(`Model: ${MODEL}`); console.log(`Jobs: ${targets.map((t) => t.id).join(', ')}`); for (const job of targets) { console.log(`\n→ ${job.id}`); try { await generate(job); } catch (err) { console.error(` ✗ ${job.id}: ${err.message}`); } } console.log('\nDone.');