Branchwell

Lumen & Gesso / website · lumengesso.com / scripts / generate-otto-landscape.mjs

Raw 4.8 KB on f4d070c0cd6547ed6432bda0f7f1dc2cb2181b18
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
7import fs from 'node:fs';
8import path from 'node:path';
9import { fileURLToPath } from 'node:url';
10
11const __dirname = path.dirname(fileURLToPath(import.meta.url));
12const ROOT = path.resolve(__dirname, '..');
13
14function 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}
30loadEnvLocal();
31
32const GEMINI_KEY = process.env.GEMINI_API_KEY;
33if (!GEMINI_KEY) {
34 console.error('GEMINI_API_KEY not set');
35 process.exit(1);
36}
37
38const REFERENCE = path.resolve(ROOT, 'public/portraits/before-otto.jpg');
39const OUT_PATH = path.resolve(ROOT, 'public/portraits/after-otto-landscape.png');
40
41const refBytes = fs.readFileSync(REFERENCE);
42const refMime = 'image/jpeg';
43const refB64 = refBytes.toString('base64');
44
45const 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
47Canvas 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
51Subject:
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
55Scene:
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
59Style:
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
66Composition 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
72The 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
74const 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
86const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image:generateContent`;
87console.log('→ generating after-otto-landscape.png (gemini-3-pro-image)');
88const 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});
93if (!r.ok) {
94 const text = await r.text();
95 console.error(`${r.status} ${r.statusText}: ${text.slice(0, 600)}`);
96 process.exit(1);
97}
98const json = await r.json();
99const parts = json?.candidates?.[0]?.content?.parts ?? [];
100let b64 = null;
101for (const part of parts) {
102 const data = part?.inline_data?.data ?? part?.inlineData?.data;
103 if (data) { b64 = data; break; }
104}
105if (!b64) {
106 console.error('No image data in Gemini response');
107 process.exit(1);
108}
109fs.writeFileSync(OUT_PATH, Buffer.from(b64, 'base64'));
110console.log(`✓ ${path.relative(ROOT, OUT_PATH)}`);