Lumen & Gesso / website · lumengesso.com / scripts / generate-otto-landscape.mjs
| 1 | #!/usr/bin/env node |
| 2 | // One-off: generate after-otto-landscape.png from before-otto.jpg. |
| 3 | // "Landscape oil style" is a legacy gallery example, not a catalog style, |
| 4 | // so this script carries its own prompt rather than wiring it through |
| 5 | // portraitPrompts.ts. |
| 6 | |
| 7 | import fs from 'node:fs'; |
| 8 | import path from 'node:path'; |
| 9 | import { fileURLToPath } from 'node:url'; |
| 10 | |
| 11 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 12 | const ROOT = path.resolve(__dirname, '..'); |
| 13 | |
| 14 | function loadEnvLocal() { |
| 15 | const p = path.join(ROOT, '.env.local'); |
| 16 | if (!fs.existsSync(p)) return; |
| 17 | for (const raw of fs.readFileSync(p, 'utf8').split('\n')) { |
| 18 | const line = raw.trim(); |
| 19 | if (!line || line.startsWith('#')) continue; |
| 20 | const eq = line.indexOf('='); |
| 21 | if (eq < 0) continue; |
| 22 | const key = line.slice(0, eq).trim(); |
| 23 | let val = line.slice(eq + 1).trim(); |
| 24 | if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) { |
| 25 | val = val.slice(1, -1); |
| 26 | } |
| 27 | if (!(key in process.env)) process.env[key] = val; |
| 28 | } |
| 29 | } |
| 30 | loadEnvLocal(); |
| 31 | |
| 32 | const GEMINI_KEY = process.env.GEMINI_API_KEY; |
| 33 | if (!GEMINI_KEY) { |
| 34 | console.error('GEMINI_API_KEY not set'); |
| 35 | process.exit(1); |
| 36 | } |
| 37 | |
| 38 | const REFERENCE = path.resolve(ROOT, 'public/portraits/before-otto.jpg'); |
| 39 | const OUT_PATH = path.resolve(ROOT, 'public/portraits/after-otto-landscape.png'); |
| 40 | |
| 41 | const refBytes = fs.readFileSync(REFERENCE); |
| 42 | const refMime = 'image/jpeg'; |
| 43 | const refB64 = refBytes.toString('base64'); |
| 44 | |
| 45 | const PROMPT = `Create a classical landscape oil-style portrait of the pet shown in the reference image — the look of a 19th-century Romantic-era oil painting on canvas, with the pet as the central subject in an autumn outdoor scene. |
| 46 | |
| 47 | Canvas requirements: |
| 48 | - 1:1 square aspect ratio (equal width and height) |
| 49 | - The artwork is a full-bleed oil painting on canvas — no border, no mat, no frame inside the image. The painted scene fills the entire canvas edge-to-edge. |
| 50 | |
| 51 | Subject: |
| 52 | - Preserve the pet's identity exactly: breed, coat colour and pattern, markings, eye colour, fur length, and distinctive features must match the reference photo |
| 53 | - Pose: pet sitting or standing in a confident 3/4 turn toward the viewer, head held high, alert, characterful |
| 54 | |
| 55 | Scene: |
| 56 | - Place the pet in a romantic autumn landscape — golden-orange foliage, soft turning leaves on the ground, a hint of distant rolling hills or a meadow, warm low-angle late-afternoon sunlight |
| 57 | - The scene composition keeps the pet as the unmistakable hero in the foreground, with the landscape behind in soft painterly falloff |
| 58 | |
| 59 | Style: |
| 60 | - Classical oil-on-canvas aesthetic in the lineage of George Stubbs, John Emms, and 19th-century pet-portrait painters |
| 61 | - Visible brushwork — soft confident strokes following fur direction and the contours of the leaves and ground |
| 62 | - Layered glazes producing a warm Old-Master colour palette: burnt sienna, ochre, raw umber, cadmium yellow accents on the leaves, soft greens in the distance, warm flesh-tones on the pet's coat |
| 63 | - Soft chiaroscuro lighting from a single warm light source — gentle shadow under the pet grounding it in the scene |
| 64 | - Visible canvas-weave texture across the painted surface |
| 65 | |
| 66 | Composition and framing — strict: |
| 67 | - The painted scene FILLS THE FULL CANVAS edge-to-edge. No empty white space, no border, no mat. |
| 68 | - Position the pet's head and eyes in the upper-middle of the canvas (about 25–35% down from the top), with comfortable breathing room above filled with foliage / sky. |
| 69 | - The pet's body fills the central composition; the landscape wraps around it. |
| 70 | - Never crop the head, ears, eyes, muzzle, or nose. |
| 71 | |
| 72 | The mood should feel warm, romantic, classical, and gallery-ready — a Romantic-era oil pet portrait you'd find hanging in an old country house.`; |
| 73 | |
| 74 | const body = { |
| 75 | contents: [ |
| 76 | { |
| 77 | parts: [ |
| 78 | { text: PROMPT }, |
| 79 | { inline_data: { mime_type: refMime, data: refB64 } }, |
| 80 | ], |
| 81 | }, |
| 82 | ], |
| 83 | generationConfig: { responseModalities: ['image', 'text'] }, |
| 84 | }; |
| 85 | |
| 86 | const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image:generateContent`; |
| 87 | console.log('→ generating after-otto-landscape.png (gemini-3-pro-image)'); |
| 88 | const r = await fetch(url, { |
| 89 | method: 'POST', |
| 90 | headers: { 'x-goog-api-key': GEMINI_KEY, 'content-type': 'application/json' }, |
| 91 | body: JSON.stringify(body), |
| 92 | }); |
| 93 | if (!r.ok) { |
| 94 | const text = await r.text(); |
| 95 | console.error(`${r.status} ${r.statusText}: ${text.slice(0, 600)}`); |
| 96 | process.exit(1); |
| 97 | } |
| 98 | const json = await r.json(); |
| 99 | const parts = json?.candidates?.[0]?.content?.parts ?? []; |
| 100 | let b64 = null; |
| 101 | for (const part of parts) { |
| 102 | const data = part?.inline_data?.data ?? part?.inlineData?.data; |
| 103 | if (data) { b64 = data; break; } |
| 104 | } |
| 105 | if (!b64) { |
| 106 | console.error('No image data in Gemini response'); |
| 107 | process.exit(1); |
| 108 | } |
| 109 | fs.writeFileSync(OUT_PATH, Buffer.from(b64, 'base64')); |
| 110 | console.log(`✓ ${path.relative(ROOT, OUT_PATH)}`); |