Lumen & Gesso / website · lumengesso.com / scripts / generate-teddy-tucker-gus.mjs
| 1 | #!/usr/bin/env node |
| 2 | // Regenerate the home-feature Teddy (now a NEW dog) and the Hannah/Renee |
| 3 | // testimonial pets (Tucker, Gus), each with THREE stages: |
| 4 | // |
| 5 | // 1) before-{id}.jpg a CASUAL amateur phone snapshot — relaxed, |
| 6 | // candid pose (deliberately NOT the portrait pose; |
| 7 | // the before doesn't need to be good) |
| 8 | // 2) after-{id}-{style}.jpg the finished portrait — RE-POSED to a |
| 9 | // dignified hero pose, painterly/pop-art, gorgeous |
| 10 | // 3) lifestyle-{id}-{style}.jpg that artwork framed on a wall in a room |
| 11 | // |
| 12 | // The before and after are the SAME dog (identity preserved) in DIFFERENT |
| 13 | // poses — the real "casual photo in → beautiful portrait out" story. |
| 14 | // |
| 15 | // node scripts/generate-teddy-tucker-gus.mjs |
| 16 | // ONLY=teddy STAGES=before node scripts/generate-teddy-tucker-gus.mjs |
| 17 | |
| 18 | import fs from 'node:fs'; |
| 19 | import path from 'node:path'; |
| 20 | import { fileURLToPath } from 'node:url'; |
| 21 | import sharp from 'sharp'; |
| 22 | |
| 23 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 24 | const ROOT = path.resolve(__dirname, '..'); |
| 25 | const PORTRAITS = path.join(ROOT, 'public/portraits'); |
| 26 | const MODEL = 'gemini-3-pro-image'; |
| 27 | const IMAGE_SIZE = process.env.GEMINI_IMAGE_SIZE || '2K'; |
| 28 | |
| 29 | function loadEnvLocal() { |
| 30 | const p = path.join(ROOT, '.env.local'); |
| 31 | if (!fs.existsSync(p)) return; |
| 32 | for (const raw of fs.readFileSync(p, 'utf8').split('\n')) { |
| 33 | const line = raw.trim(); |
| 34 | if (!line || line.startsWith('#')) continue; |
| 35 | const eq = line.indexOf('='); if (eq < 0) continue; |
| 36 | const k = line.slice(0, eq).trim(); |
| 37 | let v = line.slice(eq + 1).trim(); |
| 38 | if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) v = v.slice(1, -1); |
| 39 | if (!(k in process.env)) process.env[k] = v; |
| 40 | } |
| 41 | } |
| 42 | loadEnvLocal(); |
| 43 | const GEMINI_KEY = process.env.GEMINI_API_KEY; |
| 44 | if (!GEMINI_KEY) { console.error('GEMINI_API_KEY not set'); process.exit(1); } |
| 45 | |
| 46 | // ── Shared after-prompt builders (RE-POSE to a hero pose, keep identity) ── |
| 47 | const REPOSE = `IMPORTANT — POSE: render the dog in a dignified HERO PORTRAIT pose — sitting or standing tall in a confident 3/4 turn toward the viewer, head up, alert, composed. You MAY change the pose from the reference photo; the reference is ONLY for the dog's identity. Do NOT copy the casual snapshot pose. |
| 48 | |
| 49 | IDENTITY — keep the EXACT same dog as the reference: same breed, coat colour and markings, fur texture/length, ear shape, eye colour, nose, and distinctive features. It must be unmistakably the same dog, just beautifully posed.`; |
| 50 | |
| 51 | function painterlyOil(subject) { |
| 52 | return `Paint a rich, refined IMPASTO OIL PORTRAIT of the dog in the reference photo — a gorgeous, gallery-quality oil painting rendered ENTIRELY in confident, visible brushstrokes and thick textured paint. ${subject} |
| 53 | |
| 54 | ${REPOSE} |
| 55 | |
| 56 | PAINTERLY TREATMENT — most important: the ENTIRE portrait, INCLUDING the face and eyes, is hand-painted in expressive oil — NOT photographic. Confident directional brushstrokes follow the fur; thick impasto ridges and palette-knife highlights catch the light; the muzzle and eyes are softly blended but clearly painted. Warm, harmonious palette. It must read as ONE cohesive, finished, beautiful oil painting in the spirit of Sargent or a fine contemporary pet-portrait painter. |
| 57 | |
| 58 | STRICTLY AVOID: a photo-real face on a loose body; scratchy black scribbled lines; chaotic scraped marks; runny paint drips; bare canvas or blotchy unfinished passages. |
| 59 | |
| 60 | COMPOSITION: square 1:1, filled edge to edge. Head and chest fill the frame, eyes about a third down from the top. Lower chest melts gently into soft painterly strokes near the bottom — no hard cut-out, no drips. Soft, warm, brushed background of gentle painterly tones. Never crop the head, ears, eyes, muzzle, or nose. |
| 61 | |
| 62 | CLEAN OUTPUT: no border, frame, mat, caption, signature, watermark, or lettering — just the painting.`; |
| 63 | } |
| 64 | |
| 65 | function popArt(subject) { |
| 66 | return `Create a bold contemporary POP-ART painting of the dog in the reference photo. ${subject} |
| 67 | |
| 68 | ${REPOSE} |
| 69 | |
| 70 | STYLE: the coat reimagined in confident blocks and streaks of saturated colour (cobalt, violet, magenta, vermilion, cream, black) running along the fur, thick gestural visible brushwork, with playful polka-dot motifs scattered on a few passages. Only the COLOUR is reimagined — never the anatomy or identity. Quiet hand-painted neutral ground with a few faint muted colour blocks. |
| 71 | |
| 72 | COMPOSITION: square 1:1, filled edge to edge. Head and chest in the upper-middle; lower chest fades toward the bottom. Never crop the head, ears, eyes, muzzle, or nose. |
| 73 | |
| 74 | CLEAN OUTPUT: no border, frame, mat, caption, signature, watermark, or lettering.`; |
| 75 | } |
| 76 | |
| 77 | // Stage 3 — place the finished square artwork inside a frame on a wall. |
| 78 | function lifestylePrompt(frame, scene) { |
| 79 | return `Editorial interior photograph. Place the supplied artwork inside a ${frame}, hanging on a wall inside ${scene}. The framed artwork is the focal point — centered, clearly readable, no distortion. |
| 80 | |
| 81 | CRITICAL — the supplied square image IS the artwork: reproduce the ENTIRE supplied image inside the frame opening in full, exactly as supplied. DO NOT crop, zoom, re-compose, re-paint, or substitute it. Every corner of the supplied square is visible inside the frame. |
| 82 | |
| 83 | CRITICAL — frame profile: a SIMPLE, FLAT, THIN, CONTEMPORARY rectangular strip in the finish requested. NO 3D depth, raised molding, bevel, carved ornament, scrollwork, or antique profile — a clean flat strip a contemporary gallery uses. |
| 84 | |
| 85 | Real-world lighting and shadow on the frame; subtle wall texture. Magazine-quality interior photography, soft natural light, no people, no text overlay.`; |
| 86 | } |
| 87 | |
| 88 | const CANVAS_FLOAT = 'thin soft-white canvas float frame with a clean rectangular profile (NOT ornate, NOT carved). The painted canvas FILLS the interior of the frame EDGE-TO-EDGE — NO mat, NO matte border, NO white space around the artwork. Only a thin dark recess strip between the canvas edge and the frame moulding'; |
| 89 | const WHITE_MAT = 'thin contemporary soft-white frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving'; |
| 90 | |
| 91 | // ── Pets ───────────────────────────────────────────────────────────── |
| 92 | const PETS = [ |
| 93 | { |
| 94 | id: 'teddy', |
| 95 | before: 'before-teddy-v2.jpg', |
| 96 | after: 'after-teddy-mixedmedia-v4.jpg', |
| 97 | lifestyle: 'lifestyle-teddy-mixedmedia-v5.jpg', |
| 98 | beforePrompt: `A casual, candid iPhone SNAPSHOT of an apricot-and-cream Goldendoodle with a soft, fluffy, slightly shaggy curly teddy-bear coat, dark round eyes, and a black nose. NOT a professional photo: the dog is flopped/lying on a beige living-room sofa, relaxed, head tilted and looking slightly off to the side (not at the camera), maybe mid-blink — an ordinary moment. Imperfect amateur framing, slightly off-centre, flat ordinary indoor lighting, faint phone-camera softness. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 99 | afterPrompt: painterlyOil('SUBJECT: an apricot-and-cream Goldendoodle with a soft fluffy curly teddy-bear coat, dark round eyes, black nose — warm and endearing.'), |
| 100 | frame: CANVAS_FLOAT, |
| 101 | scene: 'a sunlit modern living room with a cream linen sofa, a warm-oak side table, and a small monstera plant — the framed canvas hangs on a soft warm-white wall', |
| 102 | }, |
| 103 | { |
| 104 | id: 'tucker', |
| 105 | before: 'before-tucker.jpg', |
| 106 | after: 'after-tucker-mixedmedia-v2.jpg', |
| 107 | lifestyle: 'lifestyle-tucker-mixedmedia-v2.jpg', |
| 108 | beforePrompt: `A casual, candid iPhone SNAPSHOT of a Golden Retriever PUPPY with a fluffy pale-gold coat, floppy ears, and a soft hopeful expression. NOT a professional photo: the puppy sits on a kitchen floor looking UP at the phone with a toy near its paws, a little clumsy and off-balance, ears askew. Imperfect amateur framing shot from above, slightly off-centre, flat ordinary kitchen lighting, faint phone-camera softness. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 109 | afterPrompt: painterlyOil('SUBJECT: a Golden Retriever puppy with a fluffy pale-gold coat, floppy ears, dark soulful eyes, and the exact hopeful "I want something" look.'), |
| 110 | frame: CANVAS_FLOAT, |
| 111 | scene: 'a sunlit modern living room with a cream linen sofa, a warm-oak coffee table with a small stack of art books, and soft daylight from a tall window — the framed canvas hangs on a soft warm-white wall above the sofa', |
| 112 | }, |
| 113 | { |
| 114 | id: 'gus', |
| 115 | before: 'before-gus.jpg', |
| 116 | after: 'after-gus-popart-v2.jpg', |
| 117 | lifestyle: 'lifestyle-gus-popart-v2.jpg', |
| 118 | beforePrompt: `A casual, candid iPhone SNAPSHOT of a Pembroke Welsh Corgi with the classic red-and-white coat, big upright ears, and a huge happy open-mouth grin with the tongue out. NOT a professional photo: the corgi stands on a sunny backyard patio caught mid-trot, body at an angle, looking off-frame, a bit of motion blur. Imperfect amateur framing, off-centre, harsh midday outdoor light. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 119 | afterPrompt: popArt('SUBJECT: a Pembroke Welsh Corgi with the classic red-and-white coat, big upright ears, and a joyful open-mouth grin — the most ridiculous, happy dog alive.'), |
| 120 | frame: WHITE_MAT, |
| 121 | scene: 'a bright, cheerful breakfast nook with a round white table, two pale-wood chairs, and crisp morning sunlight — the framed artwork hangs on a clean white wall', |
| 122 | }, |
| 123 | // ─── Befores-only for the remaining 3 testimonials (Daniel/Marcus/Sasha&Lee). |
| 124 | // Their portraits already exist on the CDN; we just need casual snapshots |
| 125 | // to pair them with, matching Hannah/Renee. Run with STAGES=before. |
| 126 | { |
| 127 | id: 'willow', |
| 128 | before: 'before-willow.jpg', |
| 129 | after: '', lifestyle: '', afterPrompt: '', frame: '', scene: '', |
| 130 | beforePrompt: `A casual, candid iPhone SNAPSHOT of an adult Border Collie with the classic black-and-white coat — black mask with a slim white blaze down the muzzle, white chest and paws, a feathered black-and-white tail. The dog stands alert on a grassy lawn in soft afternoon light, in a 3/4 turn looking AT the camera with ears up, mouth slightly open, tongue just visible — clearly mid-play, not lying down. NOT a professional photo: a little off-centre, slightly tilted horizon, ordinary outdoor light, a hint of phone-camera softness. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 131 | }, |
| 132 | { |
| 133 | id: 'nova', |
| 134 | before: 'before-nova.jpg', |
| 135 | after: '', lifestyle: '', afterPrompt: '', frame: '', scene: '', |
| 136 | beforePrompt: `A casual, candid iPhone SNAPSHOT of an adult Bernese Mountain Dog — the classic tricolour coat (jet-black body, rust-brown cheeks and legs, crisp white blaze down the muzzle, white chest), a big square head, and dark expressive eyes. The dog lies sprawled on his side on a hardwood floor at home, half on a rug, looking sleepy and lazy with one ear flopped down, paws relaxed, clearly resting NOT posed. NOT a professional photo: shot from a low angle, slightly off-centre, ordinary warm indoor lamp light. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 137 | }, |
| 138 | { |
| 139 | id: 'waffle', |
| 140 | before: 'before-waffle.jpg', |
| 141 | after: '', lifestyle: '', afterPrompt: '', frame: '', scene: '', |
| 142 | beforePrompt: `A casual, candid iPhone SNAPSHOT of a Standard Smooth-Coat Dachshund with the classic red-mahogany coat, long body and stubby legs, long floppy ears, and a long pointed muzzle with a glossy black nose. The dog is curled up nose-to-tail asleep on a tan corduroy couch cushion, eyes mostly closed, ears draped over the cushion edge, a small striped blanket nearby. NOT a professional photo: shot from above at a slight angle, slightly off-centre, soft warm window light. The kind of quick photo a real owner snaps. A genuine photograph, no illustration, no text, no border.`, |
| 143 | }, |
| 144 | ]; |
| 145 | |
| 146 | async function gemini({ prompt, refPath, aspect }) { |
| 147 | const parts = [{ text: prompt }]; |
| 148 | if (refPath) { |
| 149 | const bytes = fs.readFileSync(refPath); |
| 150 | parts.push({ inline_data: { mime_type: refPath.endsWith('.png') ? 'image/png' : 'image/jpeg', data: bytes.toString('base64') } }); |
| 151 | } |
| 152 | const imageConfig = { aspectRatio: aspect || '1:1' }; |
| 153 | if (IMAGE_SIZE && IMAGE_SIZE !== '1K') imageConfig.imageSize = IMAGE_SIZE; |
| 154 | const body = { contents: [{ parts }], generationConfig: { responseModalities: ['image', 'text'], imageConfig } }; |
| 155 | const url = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent`; |
| 156 | let lastErr; |
| 157 | for (let attempt = 1; attempt <= 2; attempt++) { |
| 158 | try { |
| 159 | const r = await fetch(url, { method: 'POST', headers: { 'x-goog-api-key': GEMINI_KEY, 'content-type': 'application/json' }, body: JSON.stringify(body) }); |
| 160 | if (!r.ok) throw new Error(`${r.status} ${r.statusText}: ${(await r.text()).slice(0, 300)}`); |
| 161 | const json = await r.json(); |
| 162 | for (const part of (json?.candidates?.[0]?.content?.parts ?? [])) { |
| 163 | const data = part?.inline_data?.data ?? part?.inlineData?.data; |
| 164 | if (data) return Buffer.from(data, 'base64'); |
| 165 | } |
| 166 | throw new Error('no image data'); |
| 167 | } catch (e) { lastErr = e; if (attempt < 2) await new Promise(r => setTimeout(r, 1500)); } |
| 168 | } |
| 169 | throw lastErr; |
| 170 | } |
| 171 | |
| 172 | async function saveJpeg(buf, outName, { maxW, maxH, quality }) { |
| 173 | const outPath = path.join(PORTRAITS, outName); |
| 174 | await sharp(buf).resize({ width: maxW, height: maxH, fit: 'inside', withoutEnlargement: true }).jpeg({ quality, mozjpeg: true }).toFile(outPath); |
| 175 | console.log(` ✓ ${outName} (${Math.round(fs.statSync(outPath).size / 1024)} KB)`); |
| 176 | } |
| 177 | |
| 178 | const ONLY = process.env.ONLY ? new Set(process.env.ONLY.split(',').map(s => s.trim())) : null; |
| 179 | const STAGES = process.env.STAGES ? new Set(process.env.STAGES.split(',').map(s => s.trim())) : new Set(['before', 'after', 'lifestyle']); |
| 180 | |
| 181 | async function runPet(pet) { |
| 182 | const beforePath = path.join(PORTRAITS, pet.before); |
| 183 | const afterPath = path.join(PORTRAITS, pet.after); |
| 184 | if (STAGES.has('before')) { |
| 185 | console.log(` [${pet.id}] before (casual snapshot)…`); |
| 186 | await saveJpeg(await gemini({ prompt: pet.beforePrompt, aspect: '3:4' }), pet.before, { maxW: 1500, maxH: 2000, quality: 86 }); |
| 187 | } |
| 188 | if (STAGES.has('after')) { |
| 189 | if (!fs.existsSync(beforePath)) throw new Error(`missing ${pet.before}`); |
| 190 | console.log(` [${pet.id}] after (hero portrait, re-posed)…`); |
| 191 | await saveJpeg(await gemini({ prompt: pet.afterPrompt, refPath: beforePath, aspect: '1:1' }), pet.after, { maxW: 2048, maxH: 2048, quality: 94 }); |
| 192 | } |
| 193 | if (STAGES.has('lifestyle')) { |
| 194 | if (!fs.existsSync(afterPath)) throw new Error(`missing ${pet.after}`); |
| 195 | console.log(` [${pet.id}] lifestyle (framed)…`); |
| 196 | await saveJpeg(await gemini({ prompt: lifestylePrompt(pet.frame, pet.scene), refPath: afterPath, aspect: '1:1' }), pet.lifestyle, { maxW: 1400, maxH: 1400, quality: 86 }); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | const targets = ONLY ? PETS.filter(p => ONLY.has(p.id)) : PETS; |
| 201 | console.log(`Model: ${MODEL} @ ${IMAGE_SIZE}\nPets: ${targets.map(p => p.id).join(', ')}\nStages: ${[...STAGES].join(', ')}\n`); |
| 202 | const results = await Promise.allSettled(targets.map(runPet)); |
| 203 | let fails = 0; |
| 204 | results.forEach((r, i) => { if (r.status === 'rejected') { fails++; console.error(` ✗ ${targets[i].id}: ${r.reason?.message || r.reason}`); } }); |
| 205 | console.log(`\nDone. ${results.length - fails}/${results.length} pets succeeded.`); |
| 206 | process.exit(fails ? 1 : 0); |