Lumen & Gesso / website · lumengesso.com / scripts / generate-lifestyle.mjs
| 1 | #!/usr/bin/env node |
| 2 | // Generate "lifestyle" gallery shots — framed portrait in a room scene. |
| 3 | // |
| 4 | // Each job takes an already-rendered after-{animal}-{style}.png style |
| 5 | // image and asks Gemini Nano Banana to compose it as a wall-mounted |
| 6 | // framed print in an interior matching the subject + style. Writes |
| 7 | // lifestyle-{animal}-{style}.jpg next to the source. |
| 8 | // |
| 9 | // Usage: |
| 10 | // GEMINI_API_KEY=AIza... node scripts/generate-lifestyle.mjs |
| 11 | // |
| 12 | // Optional: |
| 13 | // ONLY=clover-watercolor,major-lineart restrict to specific jobs |
| 14 | // |
| 15 | // The JOBS table is the single source of truth for what gets generated. |
| 16 | |
| 17 | import fs from 'node:fs'; |
| 18 | import path from 'node:path'; |
| 19 | import { fileURLToPath } from 'node:url'; |
| 20 | |
| 21 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 22 | const ROOT = path.resolve(__dirname, '..'); |
| 23 | const GEMINI_KEY = process.env.GEMINI_API_KEY; |
| 24 | if (!GEMINI_KEY) { |
| 25 | console.error('GEMINI_API_KEY is not set.'); |
| 26 | process.exit(1); |
| 27 | } |
| 28 | |
| 29 | const MODEL = 'gemini-3-pro-image'; |
| 30 | // Nano Banana Pro output tier — default to the highest (4K). Override |
| 31 | // with GEMINI_IMAGE_SIZE=1K/2K for quick, cheap test runs. |
| 32 | const GEMINI_IMAGE_SIZE = process.env.GEMINI_IMAGE_SIZE || '4K'; |
| 33 | const PORTRAITS_DIR = path.join(ROOT, 'public/portraits'); |
| 34 | const ONLY = process.env.ONLY |
| 35 | ? new Set(process.env.ONLY.split(',').map((s) => s.trim())) |
| 36 | : null; |
| 37 | |
| 38 | // Each job pairs an animal+style with a specific room/setting prompt |
| 39 | // tuned to match the artwork. The prompt always asks for the artwork |
| 40 | // hung or propped on a wall, naturally framed, with editorial lighting. |
| 41 | const JOBS = [ |
| 42 | { |
| 43 | key: 'clover-watercolor', |
| 44 | source: 'after-clover-watercolor.png', |
| 45 | out: 'lifestyle-clover-watercolor.jpg', |
| 46 | frame: 'white box frame', |
| 47 | scene: |
| 48 | 'a serene sunlit nursery corner with a pale linen sofa, a small wooden bench, and a stuffed rabbit on the floor; soft daylight from a tall window; calm pastel palette', |
| 49 | }, |
| 50 | { |
| 51 | key: 'major-lineart', |
| 52 | source: 'after-major-lineart.png', |
| 53 | out: 'lifestyle-major-lineart.jpg', |
| 54 | frame: 'matte black thin frame', |
| 55 | scene: |
| 56 | 'a modern minimalist home office with a clean white oak desk, a single brass desk lamp, and neutral wood floors; sharp morning light; uncluttered editorial composition', |
| 57 | }, |
| 58 | { |
| 59 | key: 'marlow-cubist', |
| 60 | source: 'after-marlow-cubist.png', |
| 61 | out: 'lifestyle-marlow-cubist.jpg', |
| 62 | frame: 'natural oak frame', |
| 63 | scene: |
| 64 | 'an eclectic mid-century study with a deep teal velvet armchair, a curved arc-floor lamp, and a small bookshelf with art books; warm afternoon light; gallery-collector vibe', |
| 65 | }, |
| 66 | { |
| 67 | key: 'mortimer-thangka', |
| 68 | source: 'after-mortimer-thangka.png', |
| 69 | out: 'lifestyle-mortimer-thangka-v2.jpg', |
| 70 | frame: 'thin contemporary warm-gold frame with a clean rectangular profile (NOT ornate, NOT baroque-gilt, NOT carved or decorative) and a warm-cream mat board border', |
| 71 | scene: |
| 72 | 'a botanical sunroom with terracotta pots, hanging trailing plants, a woven jute rug, and a wicker chair; dappled greenhouse light; meditative still atmosphere', |
| 73 | }, |
| 74 | { |
| 75 | key: 'sable-charcoal', |
| 76 | source: 'after-sable-charcoal.png', |
| 77 | out: 'lifestyle-sable-charcoal-v2.jpg', |
| 78 | frame: 'thin contemporary soft-white frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 79 | scene: |
| 80 | 'a calm modern bedroom corner with a soft linen reading chair, a small wood side table with a stack of art books and a ceramic mug, a leafy potted plant, and warm afternoon window light', |
| 81 | }, |
| 82 | { |
| 83 | key: 'juno-lineart', |
| 84 | source: 'after-juno-lineart.png', |
| 85 | out: 'lifestyle-juno-lineart-v3.jpg', |
| 86 | frame: 'thin contemporary soft-white frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 87 | nameOverlay: 'JUNO', |
| 88 | scene: |
| 89 | 'a modern minimalist home office with a clean white-oak desk, a single brass desk lamp, a small ceramic mug, and neutral wood floors; sharp morning light; uncluttered editorial composition', |
| 90 | }, |
| 91 | // ─── Re-renders requested in feedback round (cooper, koda, clover, hamlet) |
| 92 | { |
| 93 | key: 'cooper-vector', |
| 94 | source: 'after-cooper-vector.png', |
| 95 | out: 'lifestyle-cooper-vector-v4.jpg', |
| 96 | frame: 'thin contemporary soft-white frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 97 | scene: |
| 98 | 'a bright modern entryway with a pale-grey console table, a small ceramic bowl for keys, a leafy houseplant, and a brass wall hook — soft morning light on a weathered wood plank wall', |
| 99 | }, |
| 100 | { |
| 101 | key: 'koda-named', |
| 102 | source: 'after-koda-named.png', |
| 103 | out: 'lifestyle-koda-named-v4.jpg', |
| 104 | frame: 'thin contemporary matte-walnut frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 105 | nameOverlay: 'KODA', |
| 106 | scene: |
| 107 | 'a sunny modern living room with a soft linen sofa, a small live-edge wood side table, a leafy fiddle-leaf fig in a ceramic pot, and warm afternoon window light', |
| 108 | }, |
| 109 | { |
| 110 | key: 'clover-charcoal', |
| 111 | source: 'after-clover-charcoal.png', |
| 112 | out: 'lifestyle-clover-charcoal-v3.jpg', |
| 113 | frame: 'thin contemporary soft-white floating frame with the charcoal artwork FULL BLEED to the frame opening — NO mat board, NO matte border, NO white gap. The artwork edge meets the frame moulding directly with only a thin dark recess strip. Clean rectangular profile, NO ornament, NO depth, NO carving', |
| 114 | scene: |
| 115 | 'a serene sunlit nursery corner with a pale linen sofa, a small wood bench, a stuffed bunny on the floor, and soft daylight from a tall window — calm pastel palette', |
| 116 | }, |
| 117 | { |
| 118 | key: 'hamlet-named', |
| 119 | source: 'after-hamlet-named.png', |
| 120 | out: 'lifestyle-hamlet-named-v4.jpg', |
| 121 | frame: 'thin contemporary matte-walnut frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 122 | nameOverlay: 'HAMLET', |
| 123 | scene: |
| 124 | 'a cheerful breakfast nook with a round oak table, two mid-century dining chairs, a small ceramic vase with wildflowers, and white shiplap walls; bright morning sunlight', |
| 125 | }, |
| 126 | // ─── Risograph — small-press print-shop and modern eclectic rooms ─ |
| 127 | { |
| 128 | key: 'murph-risograph', |
| 129 | source: 'after-murph-risograph.png', |
| 130 | out: 'lifestyle-murph-risograph-v3.jpg', |
| 131 | frame: 'honey oak frame with a thin snow-white mat', |
| 132 | scene: |
| 133 | 'a bright modern print-shop studio corner with a clean wood worktable, a stack of risograph art prints leaning against the wall, an Anglepoise desk lamp, and warm afternoon window light; uncluttered editorial composition', |
| 134 | }, |
| 135 | { |
| 136 | key: 'suki-risograph', |
| 137 | source: 'after-suki-risograph.png', |
| 138 | out: 'lifestyle-suki-risograph-v3.jpg', |
| 139 | frame: 'walnut frame with a thin snow-white mat', |
| 140 | scene: |
| 141 | 'a modern eclectic living room with a deep cobalt velvet armchair, a brass arc-floor lamp, a record player on a low wood credenza, and a small monstera plant; soft afternoon light through sheer curtains', |
| 142 | }, |
| 143 | { |
| 144 | key: 'chip-risograph', |
| 145 | source: 'after-chip-risograph.png', |
| 146 | out: 'lifestyle-chip-risograph-v3.jpg', |
| 147 | frame: 'soft white box frame with a snow-white mat', |
| 148 | scene: |
| 149 | 'a small-press graphic-design studio with neutral plaster walls, a wood-topped desk, a vintage Anglepoise lamp, a stack of art books, and a clip-up of risograph prints on a wire above the desk; warm window light', |
| 150 | }, |
| 151 | // ─── Retro Home — full-on 1970s home environments around the photo |
| 152 | { |
| 153 | key: 'frank-athome', |
| 154 | source: 'after-frank-athome.png', |
| 155 | out: 'lifestyle-frank-athome-v3.jpg', |
| 156 | frame: 'thin contemporary matte-walnut frame with a clean rectangular profile (NOT ornate, NOT carved, NOT a vintage decorative frame) and a warm-cream mat board border around the artwork', |
| 157 | scene: |
| 158 | 'a quintessential 1970s den with dark walnut wood-panelled walls, a tan corduroy sectional sofa, a brass-and-amber-glass swag lamp hanging from the ceiling, a thick earth-tone shag rug, a small wood console TV in the corner, a sunburst wall clock, and a hanging macramé planter with a trailing fern; warm late-afternoon tungsten glow, lived-in 1970s collector vibe', |
| 159 | }, |
| 160 | { |
| 161 | key: 'marmalade-athome', |
| 162 | source: 'after-marmalade-athome-v3.png', |
| 163 | out: 'lifestyle-marmalade-athome-v4.jpg', |
| 164 | frame: 'honey oak frame with a warm-cream mat', |
| 165 | scene: |
| 166 | 'a bright, sunlit mid-century-modern living room with a calm warm-white wall, a low walnut credenza on tapered legs, a mid-century lounge chair in mustard velvet, a large leafy monstera in a simple ceramic planter, and a colourful patterned area rug; clean natural daylight, fresh contemporary retro-revival styling kept calm enough to let the colourful framed portrait be the focal point, NOT a dated 1970s time capsule', |
| 167 | }, |
| 168 | { |
| 169 | key: 'popcorn-athome', |
| 170 | source: 'after-popcorn-athome.png', |
| 171 | out: 'lifestyle-popcorn-athome-v3.jpg', |
| 172 | frame: 'walnut frame with a warm-cream mat', |
| 173 | scene: |
| 174 | 'a sunny 1970s breakfast nook with butter-yellow daisy-print wallpaper, a round chrome-edged formica dinette table, two harvest-gold vinyl bucket chairs, a stained-glass swag pendant lamp hanging above, gingham curtains at the window, a ceramic Merry-Mushroom canister set on a small wood shelf, and a faux brick accent wall partly visible; bright morning sunlight, cheerful 1970s diner vibe', |
| 175 | }, |
| 176 | // ─── Neo-Expressionist — downtown loft, gallery, urban modern rooms ─ |
| 177 | { |
| 178 | key: 'rex-neoexpressionist', |
| 179 | source: 'after-rex-neoexpressionist.png', |
| 180 | out: 'lifestyle-rex-neoexpressionist-v2.jpg', |
| 181 | frame: 'matte black thin frame with a black mat', |
| 182 | scene: |
| 183 | 'a moody downtown loft living room with polished concrete floors, a low-profile dark leather sofa, a tall sculptural floor lamp, and a single exposed brick wall; dramatic late-afternoon light raking across the floor', |
| 184 | }, |
| 185 | { |
| 186 | key: 'iggy-neoexpressionist', |
| 187 | source: 'after-iggy-neoexpressionist.png', |
| 188 | out: 'lifestyle-iggy-neoexpressionist-v2.jpg', |
| 189 | frame: 'matte black thin frame with a snow-white mat', |
| 190 | scene: |
| 191 | 'a sleek contemporary apartment with a white-oak floor, a marble-topped side table, a small brutalist concrete sculpture, a black accent chair, and minimal decor; dramatic directional side lighting', |
| 192 | }, |
| 193 | { |
| 194 | key: 'capy-neoexpressionist', |
| 195 | source: 'after-capy-neoexpressionist.png', |
| 196 | out: 'lifestyle-capy-neoexpressionist-v2.jpg', |
| 197 | frame: 'matte black thin frame with a black mat', |
| 198 | scene: |
| 199 | 'a high-ceilinged urban gallery space with polished concrete floors, a single low wooden bench, clean white walls, and a track-lit dramatic spotlight illuminating the artwork', |
| 200 | }, |
| 201 | // ─── Canvas-float (full-bleed, NO mat) — painted styles on canvas ── |
| 202 | { |
| 203 | key: 'teddy-mixedmedia', |
| 204 | source: 'after-teddy-mixedmedia.png', |
| 205 | out: 'lifestyle-teddy-mixedmedia-v2.jpg', |
| 206 | frame: '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, the signature canvas-float look', |
| 207 | scene: |
| 208 | 'a sunlit modern living room with a cream linen sofa, a warm-oak side table, a small monstera plant, and soft daylight from a tall window — the framed canvas hangs on a weathered wood plank wall', |
| 209 | }, |
| 210 | { |
| 211 | key: 'otto-landscape', |
| 212 | source: 'after-otto-landscape.png', |
| 213 | out: 'lifestyle-otto-landscape-v2.jpg', |
| 214 | frame: '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, the signature canvas-float look', |
| 215 | scene: |
| 216 | 'a warm country-house study with a deep brown leather wingback chair, a small wood writing desk, a brass desk lamp, rich oak floorboards, and warm afternoon light — the framed canvas hangs above the chair', |
| 217 | }, |
| 218 | { |
| 219 | key: 'bowie-popart', |
| 220 | source: 'after-bowie-popart.png', |
| 221 | out: 'lifestyle-bowie-popart-v2.jpg', |
| 222 | frame: '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, the signature canvas-float look', |
| 223 | scene: |
| 224 | 'a bright modern entryway with a pale-grey console table, a small ceramic dish for keys, and a brass wall hook — the framed canvas hangs on a weathered wood plank wall in warm window light', |
| 225 | }, |
| 226 | { |
| 227 | key: 'maple-watercolor', |
| 228 | source: 'after-maple-watercolor.png', |
| 229 | out: 'lifestyle-maple-watercolor-v2.jpg', |
| 230 | frame: 'thin soft-white canvas float frame with a clean rectangular profile (NOT ornate, NOT carved). The painted watercolor artwork 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 artwork edge and the frame moulding, the signature canvas-float look', |
| 231 | scene: |
| 232 | 'a serene sunlit reading corner with a pale linen reading chair, a small wood side table with a stack of art books, a small ceramic vase with a sprig of greenery, and a warm window — the framed artwork hangs on a soft-white wall', |
| 233 | }, |
| 234 | // ─── Gold + walnut frames re-rendered as thin contemporary profiles ─ |
| 235 | // (royal-style entries removed when the Royal Portrait style was retired) |
| 236 | { |
| 237 | key: 'tenzin-thangka', |
| 238 | source: 'after-tenzin-thangka.png', |
| 239 | out: 'lifestyle-tenzin-thangka-v3.jpg', |
| 240 | frame: 'thin contemporary warm-gold frame with a clean rectangular profile (NOT ornate, NOT baroque-gilt, NOT carved or decorative) and a warm-cream mat board border around the artwork', |
| 241 | scene: |
| 242 | 'a quiet meditation corner with a low wood platform bench, a small terracotta pot holding a fern, a woven jute floor mat, and soft afternoon daylight — the framed portrait hangs on a warm-white wall', |
| 243 | }, |
| 244 | // ─── Homepage testimonial shot — "hangs above the dining table" ───── |
| 245 | { |
| 246 | key: 'pickle-mixedmedia-dining', |
| 247 | source: 'after-pickle-mixedmedia.png', |
| 248 | out: 'lifestyle-pickle-mixedmedia-dining.jpg', |
| 249 | frame: '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, the signature canvas-float look', |
| 250 | scene: |
| 251 | 'a warm, elegant dining nook — a round walnut dining table with two upholstered linen chairs, a low ceramic bowl of eucalyptus sprigs on the table, a softly glowing pendant lamp hanging above, and gentle evening light from a nearby window; the framed canvas hangs on a soft warm-plaster wall above the table; calm, refined, lived-in collector atmosphere', |
| 252 | }, |
| 253 | // ─── Homepage testimonial CAROUSEL — five fresh customer examples ─── |
| 254 | { |
| 255 | key: 'tucker-mixedmedia', |
| 256 | source: 'after-tucker-mixedmedia.png', |
| 257 | out: 'lifestyle-tucker-mixedmedia.jpg', |
| 258 | frame: '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, the signature canvas-float look', |
| 259 | scene: |
| 260 | 'a sunlit modern living room with a cream linen sofa, a warm-oak coffee table holding a small stack of art books, a leafy potted olive tree, and soft daylight from a tall window; the framed canvas hangs on a soft warm-white wall; calm, refined, lived-in atmosphere', |
| 261 | }, |
| 262 | { |
| 263 | key: 'willow-charcoal', |
| 264 | source: 'after-willow-charcoal.png', |
| 265 | out: 'lifestyle-willow-charcoal.jpg', |
| 266 | frame: 'thin contemporary soft-white frame with a snow-white mat — clean rectangular profile, NO ornament, NO depth, NO carving', |
| 267 | scene: |
| 268 | 'a calm modern study corner with a soft grey reading chair, a small walnut side table holding a ceramic mug and a stack of books, a trailing pothos plant, and warm afternoon window light; the framed portrait hangs on a pale plaster wall', |
| 269 | }, |
| 270 | { |
| 271 | key: 'gus-popart', |
| 272 | source: 'after-gus-popart.png', |
| 273 | out: 'lifestyle-gus-popart.jpg', |
| 274 | frame: '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, the signature canvas-float look', |
| 275 | scene: |
| 276 | 'a bright, cheerful breakfast nook with a round white table, two pale-wood chairs, a small ceramic vase of tulips, and crisp morning sunlight; the framed canvas hangs on a clean white wall; fresh and upbeat atmosphere', |
| 277 | }, |
| 278 | { |
| 279 | key: 'nova-neoexpressionist', |
| 280 | source: 'after-nova-neoexpressionist.png', |
| 281 | out: 'lifestyle-nova-neoexpressionist.jpg', |
| 282 | frame: 'matte black thin frame with a black mat', |
| 283 | scene: |
| 284 | 'a moody downtown loft with polished concrete floors, a low-profile charcoal leather sofa, a tall sculptural floor lamp, and a single exposed-brick wall; dramatic late-afternoon light raking across the room', |
| 285 | }, |
| 286 | { |
| 287 | key: 'waffle-risograph', |
| 288 | source: 'after-waffle-risograph.png', |
| 289 | out: 'lifestyle-waffle-risograph.jpg', |
| 290 | frame: 'honey oak frame with a thin snow-white mat', |
| 291 | scene: |
| 292 | 'a modern eclectic living room with a deep teal velvet armchair, a brass arc floor lamp, a low walnut credenza with a record player, and a small trailing plant; soft afternoon light through sheer curtains', |
| 293 | }, |
| 294 | ]; |
| 295 | |
| 296 | async function generate(job) { |
| 297 | const srcPath = path.join(PORTRAITS_DIR, job.source); |
| 298 | const outPath = path.join(PORTRAITS_DIR, job.out); |
| 299 | if (!fs.existsSync(srcPath)) { |
| 300 | throw new Error(`source missing: ${path.relative(ROOT, srcPath)}`); |
| 301 | } |
| 302 | |
| 303 | const refBytes = fs.readFileSync(srcPath); |
| 304 | const refMime = 'image/png'; |
| 305 | const refB64 = refBytes.toString('base64'); |
| 306 | |
| 307 | const nameLine = job.nameOverlay |
| 308 | ? `\n\nLETTERING — the artwork is a named-portrait variant: in the empty upper band of the supplied artwork, LETTER the name "${job.nameOverlay}" in clean, modern, hand-painted serif lettering (warm dark ink) above the painted pet portrait. The lettering must be cleanly readable, centered horizontally, sitting in the upper third of the visible artwork inside the frame. This is the ONLY text allowed anywhere in the image. NO other text, captions, watermarks, or signatures anywhere else.` |
| 309 | : '\n\nReal-world lighting and shadow on the frame; subtle wall texture. Magazine-quality interior photography, soft natural light, no people, no text overlay.'; |
| 310 | |
| 311 | const prompt = `Editorial interior photograph. Place the supplied artwork inside a ${job.frame}, hanging on a wall (or leaning naturally against one) inside ${job.scene}. The framed artwork is the focal point — centered, clearly readable, no distortion. |
| 312 | |
| 313 | CRITICAL — the supplied image IS the artwork that goes inside the frame: the ENTIRE supplied square source image must appear inside the frame opening in full, as supplied. DO NOT CROP, TRIM, ZOOM IN ON, RE-COMPOSE, or RE-PAINT the source artwork. Every corner of the supplied square is visible inside the frame, never cut off, never extended, never re-imagined. The source image is the artwork; the room is a backdrop around it. |
| 314 | |
| 315 | CRITICAL — the supplied artwork is a finished PHOTOGRAPHIC PRINT of the customer's pet photographed inside a colourful styled room. Reproduce that ENTIRE photograph inside the frame — the pet AND its full background room/scene, every corner, exactly as supplied. DO NOT crop down to just the pet, DO NOT isolate the pet on a plain white or cream mat, DO NOT drop, blur, flatten, or replace the room background, and DO NOT substitute abstract art, a geometric print, a landscape, or any other picture. The framed print on the wall must show the COMPLETE supplied image — the pet PLUS its colourful room — exactly as given. |
| 316 | |
| 317 | CRITICAL — frame profile: the frame is a SIMPLE, FLAT, THIN, CONTEMPORARY rectangular strip in the finish requested. NO 3D depth, NO raised molding, NO bevel, NO carved ornament, NO scrollwork, NO decorative edge, NO baroque embellishment, NO gilt-relief detail, NO antique-style frame profile. Just a clean flat strip of colour / wood / metal sitting flush around the artwork — the kind of frame a contemporary gallery uses, not an antique museum frame.${nameLine}`; |
| 318 | |
| 319 | const body = { |
| 320 | contents: [ |
| 321 | { |
| 322 | parts: [ |
| 323 | { text: prompt }, |
| 324 | { inline_data: { mime_type: refMime, data: refB64 } }, |
| 325 | ], |
| 326 | }, |
| 327 | ], |
| 328 | generationConfig: { |
| 329 | responseModalities: ['image', 'text'], |
| 330 | imageConfig: { imageSize: GEMINI_IMAGE_SIZE }, |
| 331 | }, |
| 332 | }; |
| 333 | |
| 334 | const url = `https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent`; |
| 335 | const r = await fetch(url, { |
| 336 | method: 'POST', |
| 337 | headers: { |
| 338 | 'x-goog-api-key': GEMINI_KEY, |
| 339 | 'content-type': 'application/json', |
| 340 | }, |
| 341 | body: JSON.stringify(body), |
| 342 | }); |
| 343 | if (!r.ok) { |
| 344 | const text = await r.text(); |
| 345 | throw new Error(`${r.status} ${r.statusText}: ${text.slice(0, 400)}`); |
| 346 | } |
| 347 | |
| 348 | const json = await r.json(); |
| 349 | const parts = json?.candidates?.[0]?.content?.parts ?? []; |
| 350 | let b64 = null; |
| 351 | let outMime = null; |
| 352 | for (const part of parts) { |
| 353 | const data = part?.inline_data?.data ?? part?.inlineData?.data; |
| 354 | const mime = |
| 355 | part?.inline_data?.mime_type ?? |
| 356 | part?.inline_data?.mimeType ?? |
| 357 | part?.inlineData?.mime_type ?? |
| 358 | part?.inlineData?.mimeType; |
| 359 | if (data) { |
| 360 | b64 = data; |
| 361 | outMime = mime; |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | if (!b64) throw new Error('No image data in Gemini response'); |
| 366 | |
| 367 | // Gemini may return a PNG even though we want a JPG. Write the bytes |
| 368 | // as-is for now; we keep the .jpg extension since downstream Next/Image |
| 369 | // doesn't care about the extension vs actual MIME. |
| 370 | fs.writeFileSync(outPath, Buffer.from(b64, 'base64')); |
| 371 | console.log( |
| 372 | ` ✓ ${path.relative(ROOT, outPath)}${outMime ? ` (${outMime})` : ''}`, |
| 373 | ); |
| 374 | } |
| 375 | |
| 376 | const targets = ONLY ? JOBS.filter((j) => ONLY.has(j.key)) : JOBS; |
| 377 | console.log(`Model: ${MODEL}`); |
| 378 | console.log(`Jobs: ${targets.map((t) => t.key).join(', ')}`); |
| 379 | |
| 380 | for (const job of targets) { |
| 381 | console.log(`\n→ ${job.key}`); |
| 382 | try { |
| 383 | await generate(job); |
| 384 | } catch (err) { |
| 385 | console.error(` ✗ ${job.key}: ${err.message}`); |
| 386 | } |
| 387 | } |
| 388 | console.log('\nDone.'); |