Skip to content

The swiss army knife of lossless video/audio editing

Add release announcement image generator

Claude96ddf10c4e95
diff --git a/AGENTS.md b/AGENTS.md
index a4818563..c1ba9ad7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -41,4 +41,5 @@ After a GitHub release is published, draft one post per channel from `versions/<
- Start with "LosslessCut x.y.z is out", then the 1–3 most interesting changes for users, then the release link (https://github.com/mifi/lossless-cut/releases/tag/vx.y.z). Discord can take the full list.
- Plain text, no issue references. The link counts toward the limit (on X as 23 chars). A patch release that only fixes one platform can be a single line.
+- Attach an image made with `node script/releaseImage.ts <version> [--bg photo.jpg] "highlight 1" "highlight 2" "highlight 3"` (1600×900 PNG in `dist/`). Ask the user for a recent photo of theirs to use as the background (optional; it gets a dark gradient for legibility); keep highlights short so they fit on one line. Never commit the photo or the image. Add alt text, e.g. "LosslessCut 3.70.1: <highlights>".
- Post through the user's logged-in browser. Fill in the post and let the user confirm before clicking Post.
diff --git a/script/releaseImage.ts b/script/releaseImage.ts
new file mode 100644
index 00000000..f0a2853f
--- /dev/null
+++ b/script/releaseImage.ts
@@ -0,0 +1,48 @@
+// Generates an image for release announcements, see AGENTS.md "Release announcement"
+// Usage: node script/releaseImage.ts <version> [--bg photo.jpg] [--out file.png] "highlight 1" "highlight 2" ...
+import assert from 'node:assert';
+import { parseArgs } from 'node:util';
+import sharp from 'sharp';
+
+const width = 1600;
+const height = 900;
+
+const { values: { bg, out }, positionals: [version, ...highlights] } = parseArgs({
+ allowPositionals: true,
+ options: { bg: { type: 'string' }, out: { type: 'string' } },
+});
+assert(version != null && highlights.length <= 3, 'Usage: releaseImage.ts <version> [--bg photo.jpg] [--out file.png] [up to 3 highlights]');
+
+const escapeXml = (str: string) => str.replaceAll(/[<>&'"]/g, (c) => `&#${c.codePointAt(0)};`);
+
+const font = 'Helvetica Neue, Helvetica, Arial, sans-serif';
+const left = 110;
+
+const overlay = `<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
+ <defs>
+ <linearGradient id="shade" x1="0" x2="1" y1="0" y2="0">
+ <stop offset="0" stop-color="#000" stop-opacity="0.85" />
+ <stop offset="0.6" stop-color="#000" stop-opacity="0.55" />
+ <stop offset="1" stop-color="#000" stop-opacity="0.15" />
+ </linearGradient>
+ </defs>
+ <rect width="100%" height="100%" fill="url(#shade)" />
+ <text x="${left + 140}" y="205" font-family="${font}" font-size="64" font-weight="300" fill="#fff">LosslessCut</text>
+ <text x="${left}" y="400" font-family="${font}" font-size="150" font-weight="700" fill="#fff">${escapeXml(version)}</text>
+ ${highlights.map((highlight, i) => `<text x="${left}" y="${510 + i * 70}" font-family="${font}" font-size="44" fill="#fff" fill-opacity="0.92">• ${escapeXml(highlight)}</text>`).join('\n ')}
+ <text x="${left}" y="${height - 80}" font-family="${font}" font-size="36" fill="#fff" fill-opacity="0.75">losslesscut.app</text>
+</svg>`;
+
+// Without a photo, use a dark gradient in the app's colors
+const background = bg != null
+ ? sharp(bg).rotate().resize(width, height, { fit: 'cover' })
+ : sharp(Buffer.from(`<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="g" x1="0" x2="1" y1="0" y2="1"><stop offset="0" stop-color="#1a1d29" /><stop offset="1" stop-color="#3b2a5c" /></linearGradient></defs><rect width="100%" height="100%" fill="url(#g)" /></svg>`));
+
+const icon = await sharp('src/renderer/src/icon.svg').resize(110, 110).png().toBuffer();
+
+const outPath = out ?? `dist/release-${version}.png`;
+await background
+ .composite([{ input: Buffer.from(overlay) }, { input: icon, left, top: 125 }])
+ .png()
+ .toFile(outPath);
+console.log('Wrote', outPath);