This repository has no description
1// renders the dolly logo (public/apple-touch-icon.png) as ascii art
2// and prints it, ready to paste into the hero.image.html <pre> in
3// src/content/docs/index.mdx:
4//
5// node scripts/gen-ascii-dolly.mjs
6import { dirname, join } from "node:path";
7import { fileURLToPath } from "node:url";
8import sharp from "sharp";
9
10// monospace glyphs are roughly twice as tall as they are wide
11const COLS = 46;
12const ROWS = 23;
13const RAMP = " .:-=+*#%@";
14
15const root = join(dirname(fileURLToPath(import.meta.url)), "..");
16const png = join(root, "public", "apple-touch-icon.png");
17
18const { data, info } = await sharp(png)
19 .resize(COLS, ROWS, { fit: "fill" })
20 .ensureAlpha()
21 .raw()
22 .toBuffer({ resolveWithObject: true });
23
24const lines = [];
25for (let y = 0; y < info.height; y++) {
26 let line = "";
27 for (let x = 0; x < info.width; x++) {
28 const alpha = data[(y * info.width + x) * 4 + 3];
29 line += RAMP[Math.round((alpha / 255) * (RAMP.length - 1))];
30 }
31 lines.push(line.trimEnd());
32}
33
34console.log(lines.join("\n").replace(/^\n+|\n+$/g, ""));