PulseCanvas / app · pulsecanvas.ai / assets / app-store / mobile-marketing-1.1.5 / render-header.mjs
| 1 | // Renders the search-results image and the looping header animation. |
| 2 | // Usage: PLAYWRIGHT=/path/to/playwright/index.mjs node render-header.mjs [stills|video] [header|header-dark] |
| 3 | import { fileURLToPath, pathToFileURL } from 'node:url'; |
| 4 | import { dirname, join } from 'node:path'; |
| 5 | import { mkdirSync, rmSync } from 'node:fs'; |
| 6 | import { execFileSync } from 'node:child_process'; |
| 7 | |
| 8 | const { chromium } = await import(process.env.PLAYWRIGHT ?? 'playwright'); |
| 9 | const here = dirname(fileURLToPath(import.meta.url)); |
| 10 | const mode = process.argv[2] ?? 'stills'; |
| 11 | const variant = process.argv[3] ?? 'header'; // header (light) or header-dark |
| 12 | const suffix = variant === 'header' ? '' : '-' + variant.replace('header-', ''); |
| 13 | const fps = 30, loop = 12; |
| 14 | const out = join(here, 'release', 'en-US'); |
| 15 | mkdirSync(out, { recursive: true }); |
| 16 | const browser = await chromium.launch(); |
| 17 | |
| 18 | const search = await browser.newPage({ viewport: { width: 3840, height: 2560 } }); |
| 19 | await search.goto(pathToFileURL(join(here, 'search.html')).href); |
| 20 | await search.evaluate(() => Promise.all([...document.images].map(i => i.decode()))); |
| 21 | await search.screenshot({ path: join(out, 'search-results-3840x2560.png') }); |
| 22 | |
| 23 | const page = await browser.newPage({ viewport: { width: 3840, height: 1646 } }); |
| 24 | await page.goto(pathToFileURL(join(here, variant + '.html')).href + `?loop=${loop}`); |
| 25 | await page.evaluate(() => Promise.all([...document.images].map(i => i.decode()))); |
| 26 | if (mode === 'stills') { |
| 27 | for (const t of [0, 4, 8]) { await page.evaluate(t => render(t), t); await page.screenshot({ path: join(here, `${variant}-t${t}.png`) }); } |
| 28 | } else { |
| 29 | const frames = join(here, '.header-frames'); |
| 30 | rmSync(frames, { recursive: true, force: true }); mkdirSync(frames, { recursive: true }); |
| 31 | for (let i = 0; i < fps * loop; i++) { |
| 32 | await page.evaluate(t => render(t), i / fps); |
| 33 | await page.screenshot({ path: join(frames, String(i).padStart(4, '0') + '.png') }); |
| 34 | } |
| 35 | execFileSync('ffmpeg', ['-v', 'error', '-y', '-framerate', String(fps), '-i', join(frames, '%04d.png'), '-c:v', 'libx264', '-profile:v', 'high', '-crf', '14', '-preset', 'slow', '-pix_fmt', 'yuv420p', '-movflags', '+faststart', '-an', join(out, `header-animated${suffix}-3840x1646.mp4`)]); |
| 36 | rmSync(frames, { recursive: true, force: true }); |
| 37 | } |
| 38 | await browser.close(); |