Skip to content

Instantly share code, notes, and snippets.

@nexpr
Created August 19, 2023 09:22
Show Gist options
  • Save nexpr/f538e0ef21b6a2a1c8e95ccb58796c5e to your computer and use it in GitHub Desktop.
Save nexpr/f538e0ef21b6a2a1c8e95ccb58796c5e to your computer and use it in GitHub Desktop.
create dummy images using node.js
const fs = require("fs")
const { createCanvas } = require("canvas")
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
const chars = alphabets + alphabets.toLowerCase() + "1234567890"
for (const [index, char] of [...chars].entries()) {
const canvas = createCanvas(80, 80)
const ctx = canvas.getContext("2d")
ctx.font = "bold 70px serif"
ctx.textAlign = "center"
ctx.fillText(char, 40, 70)
const buf = canvas.toBuffer("image/png")
fs.writeFileSync(`${String(index).padStart(2, "0")}-${char}.png`, buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment