// renders the dolly logo (public/apple-touch-icon.png) as ascii art // and prints it, ready to paste into the hero.image.html
 in
// src/content/docs/index.mdx:
//
//   node scripts/gen-ascii-dolly.mjs
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import sharp from "sharp";

// monospace glyphs are roughly twice as tall as they are wide
const COLS = 46;
const ROWS = 23;
const RAMP = " .:-=+*#%@";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const png = join(root, "public", "apple-touch-icon.png");

const { data, info } = await sharp(png)
  .resize(COLS, ROWS, { fit: "fill" })
  .ensureAlpha()
  .raw()
  .toBuffer({ resolveWithObject: true });

const lines = [];
for (let y = 0; y < info.height; y++) {
  let line = "";
  for (let x = 0; x < info.width; x++) {
    const alpha = data[(y * info.width + x) * 4 + 3];
    line += RAMP[Math.round((alpha / 255) * (RAMP.length - 1))];
  }
  lines.push(line.trimEnd());
}

console.log(lines.join("\n").replace(/^\n+|\n+$/g, ""));