Branchwell

Lumen & Gesso / website · lumengesso.com / scripts / generate-juno-lineart.mjs

1#!/usr/bin/env node
2// One-off: re-render after-juno-lineart.png as an upright portrait,
3// not the curled overhead pose of the source photo. The standard LINEART
4// prompt's "reinterpret as upright" hint isn't strong enough when the
5// reference is a tightly-curled overhead candid; this script bolts on
6// explicit anti-overhead language and routes through Gemini, which
7// follows pose-override instructions more literally than gpt-image-2.
8
9import fs from 'node:fs';
10import path from 'node:path';
11import { fileURLToPath } from 'node:url';
12
13const __dirname = path.dirname(fileURLToPath(import.meta.url));
14const ROOT = path.resolve(__dirname, '..');
15
16function loadEnvLocal() {
17 const p = path.join(ROOT, '.env.local');
18 if (!fs.existsSync(p)) return;
19 for (const raw of fs.readFileSync(p, 'utf8').split('\n')) {
20 const line = raw.trim();
21 if (!line || line.startsWith('#')) continue;
22 const eq = line.indexOf('=');
23 if (eq < 0) continue;
24 const key = line.slice(0, eq).trim();
25 let val = line.slice(eq + 1).trim();
26 if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
27 val = val.slice(1, -1);
28 }
29 if (!(key in process.env)) process.env[key] = val;
30 }
31}
32loadEnvLocal();
33
34const GEMINI_KEY = process.env.GEMINI_API_KEY;
35if (!GEMINI_KEY) { console.error('GEMINI_API_KEY not set'); process.exit(1); }
36
37const REFERENCE = path.resolve(ROOT, 'public/portraits/before-juno.jpg');
38const OUT_PATH = path.resolve(ROOT, 'public/portraits/after-juno-lineart.png');
39
40const refBytes = fs.readFileSync(REFERENCE);
41const refB64 = refBytes.toString('base64');
42
43const PROMPT = `Create a refined, richly detailed black line-drawing portrait of the dog shown in the reference photo — the look of a polished editorial pen-and-ink illustration.
44
45POSE OVERRIDE — CRITICAL:
46- The reference photo shows the dog curled up on a sofa, photographed from a high overhead angle. IGNORE this candid pose entirely.
47- Render the dog as an UPRIGHT PORTRAIT HERO POSE — sitting or standing, body squared toward the viewer in a soft 3/4 turn, head HELD HIGH and alert, ears upright, gaze directed at the viewer (or slightly upward). The dog is facing the camera at eye level — NOT curled, NOT lying down, NOT viewed from above.
48- Head-and-shoulders / bust crop centred in the canvas. Long Italian Greyhound silhouette: slender neck, deep narrow chest, long muzzle, large eyes, folded rose-shaped ears. Preserve the breed identity, coat colour (soft grey-blue), eye colour, and characterful expression.
49
50Use the reference photo ONLY for the pet's identity (breed, coat, markings, eye colour, ears, expression). IGNORE the sofa, blanket, window, books, and surrounding environment entirely.
51
52Style requirements:
53- Refined black ink line drawing — confident, deliberate strokes with rich generous detail; substantial linework, NOT a sparse one-line minimalist sketch
54- Layered contour lines for fur direction, with closely-spaced parallel hatching for shadow depth under the chin, behind the ears, around the eyes
55- The eyes are the most detailed area — irises, pupils, eyelid lines, small reserved highlight as negative space
56- All lines pure black on flat #FFFFFF white — no off-white tint, no paper texture, no gradient, no halo
57
58Canvas + composition:
59- 1:1 square aspect, opaque PNG, pure flat #FFFFFF background, only the ink strokes carry darker pixels
60- Centre the bust portrait — head and shoulders fill the central composition with comfortable margins all around. Position the eyes at roughly the upper third of the canvas.
61- NO borders, frames, props, decorative elements, or text of any kind`;
62
63const body = {
64 contents: [{ parts: [
65 { text: PROMPT },
66 { inline_data: { mime_type: 'image/jpeg', data: refB64 } },
67 ] }],
68 generationConfig: { responseModalities: ['image', 'text'] },
69};
70
71console.log('→ Gemini render: after-juno-lineart.png (upright portrait override)');
72const r = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image:generateContent', {
73 method: 'POST',
74 headers: { 'x-goog-api-key': GEMINI_KEY, 'content-type': 'application/json' },
75 body: JSON.stringify(body),
76});
77if (!r.ok) { console.error(`${r.status}: ${(await r.text()).slice(0, 400)}`); process.exit(1); }
78const json = await r.json();
79const parts = json?.candidates?.[0]?.content?.parts ?? [];
80let b64 = null;
81for (const part of parts) {
82 const data = part?.inline_data?.data ?? part?.inlineData?.data;
83 if (data) { b64 = data; break; }
84}
85if (!b64) { console.error('No image in response'); process.exit(1); }
86fs.writeFileSync(OUT_PATH, Buffer.from(b64, 'base64'));
87console.log(`✓ ${path.relative(ROOT, OUT_PATH)}`);