30 lines
1.9 KiB
JavaScript
30 lines
1.9 KiB
JavaScript
// Deterministic 1200x630 link preview from the app icon and synthetic UI captures.
|
|
import { readFile } from 'node:fs/promises';
|
|
import sharp from 'sharp';
|
|
|
|
const root = new URL('../', import.meta.url);
|
|
const background = Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630">
|
|
<defs><radialGradient id="glow"><stop stop-color="#6d4aff" stop-opacity=".35"/><stop offset="1" stop-color="#6d4aff" stop-opacity="0"/></radialGradient></defs>
|
|
<rect width="1200" height="630" fill="#100e17"/><ellipse cx="900" cy="300" rx="600" ry="500" fill="url(#glow)"/>
|
|
<g font-family="Adwaita Sans" fill="#f4f2fa">
|
|
<text x="72" y="265" font-size="58" font-weight="800">Proton Gallery</text>
|
|
<text x="74" y="331" font-size="30" fill="#c7b7ff">Your photos.</text>
|
|
<text x="74" y="374" font-size="30" fill="#c7b7ff">Your Proton Drive.</text>
|
|
<text x="74" y="505" font-size="22" fill="#aaa4bd">Photos · Backup · Drive galleries</text>
|
|
<text x="74" y="548" font-size="20" fill="#aaa4bd">Android 12+ · Open source</text>
|
|
</g></svg>`);
|
|
|
|
async function phone(name, width, height) {
|
|
const shot = await sharp(new URL(`src/assets/screenshots/${name}.png`, root).pathname)
|
|
.resize({ width }).extract({ left: 0, top: 0, width, height }).png().toBuffer();
|
|
const mask = Buffer.from(`<svg width="${width}" height="${height}"><rect width="${width}" height="${height}" rx="18" fill="white"/></svg>`);
|
|
return sharp(shot).composite([{ input: mask, blend: 'dest-in' }]).png().toBuffer();
|
|
}
|
|
|
|
await sharp(background).composite([
|
|
{ input: await sharp(await readFile(new URL('public/logo.svg', root))).resize(112).png().toBuffer(), left: 62, top: 82 },
|
|
{ input: await phone('backup', 220, 450), left: 638, top: 120 },
|
|
{ input: await phone('photos', 260, 528), left: 870, top: 50 },
|
|
]).png({ compressionLevel: 9 }).toFile(new URL('public/og.png', root).pathname);
|
|
console.log('wrote public/og.png');
|