Skip to content

Commit ca2357d

Browse files
committed
Add organization profile banner
0 parents  commit ca2357d

8 files changed

Lines changed: 115 additions & 0 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Build banner
2+
on:
3+
schedule: [{cron: "0 3 * * *"}]
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
paths: [scripts/**, package.json, package-lock.json, assets/wordmark.svg, .github/workflows/build.yml]
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 22
18+
cache: npm
19+
- run: sudo apt-get install -y --no-install-recommends fonts-dejavu-core
20+
- run: npm ci
21+
- run: npm run build
22+
- name: Commit changes
23+
run: |
24+
git config user.name "github-actions[bot]"
25+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
26+
git add profile/banner.png
27+
git diff --cached --quiet || (git commit -m "Update banner" && git push)

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

‎assets/wordmark.svg‎

Lines changed: 1 addition & 0 deletions
Loading

‎package-lock.json‎

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "imagescript-org-profile",
3+
"private": true,
4+
"type": "module",
5+
"scripts": { "build": "node scripts/build.mjs" },
6+
"engines": { "node": ">=22.13" },
7+
"dependencies": { "imagescript": "^3.20.3" }
8+
}

‎profile/README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div align="center">
2+
<a href="https://github.com/imagescript/ImageScript">
3+
<img src="https://raw.githubusercontent.com/imagescript/.github/main/profile/banner.png" width="900" alt="ImageScript: pure TypeScript image processing that runs everywhere.">
4+
</a>
5+
</div>

‎profile/banner.png‎

104 KB
Loading

‎scripts/build.mjs‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Builds profile/banner.png, rendered with ImageScript itself
2+
import { Image } from 'imagescript';
3+
import { readFileSync, writeFileSync } from 'node:fs';
4+
5+
const root = new URL('../', import.meta.url).pathname;
6+
const fontDir = process.env.FONT_DIR ?? '/usr/share/fonts/truetype/dejavu/';
7+
const fonts = ['DejaVuSansMono.ttf', 'DejaVuSansMono-Bold.ttf', 'DejaVuSans.ttf', 'DejaVuSans-Bold.ttf'].map((f) => readFileSync(fontDir + f));
8+
const version = JSON.parse(readFileSync(root + 'node_modules/imagescript/package.json', 'utf8')).version;
9+
const MONO = 'font-family="DejaVu Sans Mono, monospace"', SANS = 'font-family="DejaVu Sans, sans-serif"';
10+
const FG = '#F2F4F8', DIM = '#9aa3b5';
11+
const render = async (name, svg) => writeFileSync(root + 'profile/' + name, await (await Image.renderSVG(svg, { fonts, size: 2 })).encodePNG());
12+
13+
// ---- banner: live numbers, new pixel pattern every day ----
14+
{
15+
const BG = '#141821', BRAND = ['#FFC857', '#FF8C61', '#E85D8C', '#8E6CEF', '#4C7DF0'];
16+
let stars = 0, npm = 0, cdn = 0, jsr = 0;
17+
const j = async (u) => { const r = await fetch(u); if (!r.ok) throw new Error(u + ' ' + r.status); return r.json(); };
18+
stars = (await j('https://api.github.com/repos/matmen/ImageScript')).stargazers_count;
19+
npm = (await j('https://api.npmjs.org/downloads/point/last-month/imagescript')).downloads; // last 30 days
20+
cdn = (await j('https://data.jsdelivr.com/v1/stats/packages/npm/imagescript?period=month')).hits.total; // last 30 days
21+
const rows = (await j('https://api.jsr.io/scopes/matmen/packages/imagescript/downloads')).total;
22+
const cut = Math.max(...rows.map((r) => Date.parse(r.timeBucket))) - 30 * 864e5;
23+
jsr = rows.filter((r) => r.kind === 'npm_tarball' && Date.parse(r.timeBucket) > cut).reduce((n, r) => n + r.count, 0); // jsr_meta is metadata, not downloads
24+
const total = npm + cdn + jsr;
25+
const k = (n) => (n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : Math.round(n / 1000) + 'k');
26+
console.log('downloads 30d:', npm, cdn, jsr, '=', total);
27+
28+
let seed = (Math.floor(Date.now() / 864e5) * 2654435761) >>> 0;
29+
const rnd = () => (seed = (seed * 1664525 + 1013904223) >>> 0) / 2 ** 32;
30+
const wordmark = 'data:image/svg+xml;base64,' + readFileSync(root + 'assets/wordmark.svg').toString('base64');
31+
const W = 900, H = 280;
32+
let b = `<rect width="${W}" height="${H}" rx="14" fill="${BG}"/>`;
33+
for (let x = 30; x < 45; x++) for (let y = 0; y < 14; y++) {
34+
const fall = Math.min(1, (x - 29) / 13);
35+
if (rnd() < fall * 0.92) {
36+
const t = Math.min(4, Math.floor(((x - 30) / 15 * 0.6 + y / 14 * 0.4) * 5));
37+
b += `<rect x="${x * 20 + 2}" y="${y * 20 + 2}" width="16" height="16" rx="4" fill="${BRAND[t]}" opacity="${(0.12 + rnd() * 0.7).toFixed(2)}"/>`;
38+
}
39+
}
40+
b += `<image href="${wordmark}" x="40" y="34" width="405" height="70"/>`;
41+
b += `<text x="46" y="140" ${SANS} font-size="18" fill="${FG}">Pure TypeScript image processing that runs everywhere.</text>`;
42+
[[`${stars} ★`, 'on GitHub', 0], [k(total), 'downloads, last 30 days', 170], ['2020', 'since', 400]].forEach(([v, l, dx]) => {
43+
b += `<text x="${46 + dx}" y="196" ${MONO} font-size="30" font-weight="bold" fill="${FG}">${v}</text><text x="${46 + dx}" y="218" ${MONO} font-size="12" fill="${DIM}">${l}</text>`;
44+
});
45+
b += `<rect x="46" y="236" width="40" height="3" rx="1.5" fill="${BRAND[0]}"/><rect x="90" y="236" width="40" height="3" rx="1.5" fill="${BRAND[2]}"/><rect x="134" y="236" width="40" height="3" rx="1.5" fill="${BRAND[4]}"/>`;
46+
b += `<text x="46" y="262" ${MONO} font-size="12" fill="${DIM}">rendered with ImageScript v${version}</text>`;
47+
await render('banner.png', `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}">${b}</svg>`);
48+
}

0 commit comments

Comments
 (0)