Kit: formato historia 9:16 (spec.height) y pésame Urda en vertical

This commit is contained in:
Claude (PNH) 2026-10-28 14:40:41 +00:00
parent 96dc771cd3
commit c54e393fc6
No known key found for this signature in database
3 changed files with 33 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
// PNH · generador de carteles 1080x1080 con el marco oficial. // PNH · generador de carteles con el marco oficial. spec.height: 1080 (feed, por defecto) o 1920 (historia 9:16).
// Uso: node render.mjs spec.json // Uso: node render.mjs spec.json
// spec = { out: "dir", prefix: "nombre", footerLeft: "29N · VOTO EN BLANCO", numbered: true, // spec = { out: "dir", prefix: "nombre", footerLeft: "29N · VOTO EN BLANCO", numbered: true,
// slides: [ { html: "<div class='txt'>...</div>", cross: 0.13, halo: false, footer: true } ] } // slides: [ { html: "<div class='txt'>...</div>", cross: 0.13, halo: false, footer: true } ] }
@ -29,7 +29,8 @@ function raggedBar(x0, y0, x1, y1, w) {
} }
return 'M' + pts.map(p => p.map(v => v.toFixed(1)).join(',')).join('L') + 'Z'; return 'M' + pts.map(p => p.map(v => v.toFixed(1)).join(',')).join('L') + 'Z';
} }
const CROSS = raggedBar(-60, -60, 1140, 1140, 110) + raggedBar(1140, -60, -60, 1140, 110); const H = spec.height || 1080;
const CROSS = raggedBar(-60, -60, 1140, H + 60, 110) + raggedBar(1140, -60, -60, H + 60, 110);
const css = ` const css = `
@font-face{font-family:Cinzel;font-weight:700;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-700-normal.woff2')})} @font-face{font-family:Cinzel;font-weight:700;src:url(data:font/woff2;base64,${font('cinzel/files/cinzel-latin-700-normal.woff2')})}
@ -39,7 +40,7 @@ const css = `
@font-face{font-family:Garamond;font-style:italic;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-italic.woff2')})} @font-face{font-family:Garamond;font-style:italic;font-weight:500;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-500-italic.woff2')})}
@font-face{font-family:Garamond;font-style:italic;font-weight:600;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-600-italic.woff2')})} @font-face{font-family:Garamond;font-style:italic;font-weight:600;src:url(data:font/woff2;base64,${font('eb-garamond/files/eb-garamond-latin-600-italic.woff2')})}
html,body{margin:0;background:#2a0508} html,body{margin:0;background:#2a0508}
.s{position:relative;width:1080px;height:1080px;overflow:hidden;color:#FBF3E4} .s{position:relative;width:1080px;height:${H}px;overflow:hidden;color:#FBF3E4}
.s>svg{position:absolute;inset:0} .s>svg{position:absolute;inset:0}
/* bloque de texto estándar (zona útil 96..984 x 215..930) */ /* bloque de texto estándar (zona útil 96..984 x 215..930) */
.txt{position:absolute;left:96px;right:96px;top:215px;bottom:150px;display:flex;flex-direction:column;justify-content:center;gap:34px} .txt{position:absolute;left:96px;right:96px;top:215px;bottom:150px;display:flex;flex-direction:column;justify-content:center;gap:34px}
@ -63,22 +64,22 @@ p b,.gold{font-weight:600;color:#F2C64B}
function frame(i, n, sl) { function frame(i, n, sl) {
const footer = sl.footer === false ? '' : ` const footer = sl.footer === false ? '' : `
<line x1="90" y1="968" x2="990" y2="968" stroke="#D9A63A" stroke-width="1"/> <line x1="90" y1="${H - 112}" x2="990" y2="${H - 112}" stroke="#D9A63A" stroke-width="1"/>
<text x="${spec.footerCenter ? 540 : 96}" y="1008" ${spec.footerCenter ? 'text-anchor="middle"' : ''} font-family="Cinzel" font-weight="700" font-size="${spec.footerCenter ? 22 : 20}" fill="#D9A63A" letter-spacing="4">${sl.footerText || spec.footerLeft || ''}</text> <text x="${spec.footerCenter ? 540 : 96}" y="${H - 72}" ${spec.footerCenter ? 'text-anchor="middle"' : ''} font-family="Cinzel" font-weight="700" font-size="${spec.footerCenter ? 22 : 20}" fill="#D9A63A" letter-spacing="4">${sl.footerText || spec.footerLeft || ''}</text>
${spec.numbered && n > 1 ? `<text x="984" y="1008" text-anchor="end" font-family="Cinzel" font-weight="700" font-size="20" fill="#D9A63A" letter-spacing="3">${i} / ${n}${i < n ? ' →' : ''}</text>` : ''}`; ${spec.numbered && n > 1 ? `<text x="984" y="${H - 72}" text-anchor="end" font-family="Cinzel" font-weight="700" font-size="20" fill="#D9A63A" letter-spacing="3">${i} / ${n}${i < n ? ' →' : ''}</text>` : ''}`;
return `<svg width="1080" height="1080" viewBox="0 0 1080 1080" xmlns="http://www.w3.org/2000/svg"> return `<svg width="1080" height="${H}" viewBox="0 0 1080 ${H}" xmlns="http://www.w3.org/2000/svg">
<defs> <defs>
<radialGradient id="bg" cx="50%" cy="55%" r="75%"><stop offset="0" stop-color="#6a0a14"/><stop offset=".55" stop-color="#4B0000"/><stop offset="1" stop-color="#220306"/></radialGradient> <radialGradient id="bg" cx="50%" cy="55%" r="75%"><stop offset="0" stop-color="#6a0a14"/><stop offset=".55" stop-color="#4B0000"/><stop offset="1" stop-color="#220306"/></radialGradient>
<linearGradient id="gold" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFE9A6"/><stop offset=".45" stop-color="#F2C64B"/><stop offset="1" stop-color="#C9962C"/></linearGradient> <linearGradient id="gold" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#FFE9A6"/><stop offset=".45" stop-color="#F2C64B"/><stop offset="1" stop-color="#C9962C"/></linearGradient>
<radialGradient id="halo"><stop offset="0" stop-color="#F2C64B" stop-opacity=".35"/><stop offset="1" stop-color="#F2C64B" stop-opacity="0"/></radialGradient> <radialGradient id="halo"><stop offset="0" stop-color="#F2C64B" stop-opacity=".35"/><stop offset="1" stop-color="#F2C64B" stop-opacity="0"/></radialGradient>
<clipPath id="inner"><rect x="44" y="44" width="992" height="992"/></clipPath> <clipPath id="inner"><rect x="44" y="44" width="992" height="${H - 88}"/></clipPath>
</defs> </defs>
<rect width="1080" height="1080" fill="url(#bg)"/> <rect width="1080" height="${H}" fill="url(#bg)"/>
<g clip-path="url(#inner)"><path d="${CROSS}" fill="#A10F2B" opacity="${sl.cross ?? .16}"/></g> <g clip-path="url(#inner)"><path d="${CROSS}" fill="#A10F2B" opacity="${sl.cross ?? .16}"/></g>
${sl.halo ? `<circle cx="${sl.halo[0]}" cy="${sl.halo[1]}" r="${sl.halo[2]}" fill="url(#halo)"/>` : ''} ${sl.halo ? `<circle cx="${sl.halo[0]}" cy="${sl.halo[1]}" r="${sl.halo[2]}" fill="url(#halo)"/>` : ''}
${sl.svg || ''} ${sl.svg || ''}
<rect x="26" y="26" width="1028" height="1028" fill="none" stroke="#D9A63A" stroke-width="4"/> <rect x="26" y="26" width="1028" height="${H - 52}" fill="none" stroke="#D9A63A" stroke-width="4"/>
<rect x="38" y="38" width="1004" height="1004" fill="none" stroke="#D9A63A" stroke-width="1.5"/> <rect x="38" y="38" width="1004" height="${H - 76}" fill="none" stroke="#D9A63A" stroke-width="1.5"/>
<g font-family="Cinzel" font-weight="700" font-size="27" fill="url(#gold)" letter-spacing="3"> <g font-family="Cinzel" font-weight="700" font-size="27" fill="url(#gold)" letter-spacing="3">
<text x="460" y="104" text-anchor="end">PARTIDO NACIONAL</text> <text x="460" y="104" text-anchor="end">PARTIDO NACIONAL</text>
<text x="620" y="104" text-anchor="start">HISPANISTA</text> <text x="620" y="104" text-anchor="start">HISPANISTA</text>
@ -93,7 +94,7 @@ ${footer}
const out = path.resolve(path.dirname(process.argv[2]), spec.out || '.'); const out = path.resolve(path.dirname(process.argv[2]), spec.out || '.');
fs.mkdirSync(out, { recursive: true }); fs.mkdirSync(out, { recursive: true });
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM || '/opt/pw-browsers/chromium' }); const browser = await chromium.launch({ executablePath: process.env.CHROMIUM || '/opt/pw-browsers/chromium' });
const pg = await browser.newPage({ viewport: { width: 1080, height: 1080 }, deviceScaleFactor: spec.scale || 1 }); const pg = await browser.newPage({ viewport: { width: 1080, height: H }, deviceScaleFactor: spec.scale || 1 });
const n = spec.slides.length, files = []; const n = spec.slides.length, files = [];
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
const sl = spec.slides[i]; const sl = spec.slides[i];
@ -101,7 +102,7 @@ for (let i = 0; i < n; i++) {
await pg.setContent(`<!doctype html><html><head><meta charset="utf-8"><style>${css}${spec.css || ''}</style></head><body><div class="s">${frame(i + 1, n, sl)}${html}</div></body></html>`); await pg.setContent(`<!doctype html><html><head><meta charset="utf-8"><style>${css}${spec.css || ''}</style></head><body><div class="s">${frame(i + 1, n, sl)}${html}</div></body></html>`);
await pg.evaluate(() => document.fonts.ready); await pg.waitForTimeout(150); await pg.evaluate(() => document.fonts.ready); await pg.waitForTimeout(150);
const f = path.join(out, `${spec.prefix || 'pnh'}${n > 1 ? '_' + (i + 1) : ''}.png`); const f = path.join(out, `${spec.prefix || 'pnh'}${n > 1 ? '_' + (i + 1) : ''}.png`);
await pg.screenshot({ path: f, clip: { x: 0, y: 0, width: 1080, height: 1080 } }); await pg.screenshot({ path: f, clip: { x: 0, y: 0, width: 1080, height: H } });
files.push(f); files.push(f);
} }
await browser.close(); await browser.close();