Created
August 19, 2023 09:22
-
-
Save nexpr/f538e0ef21b6a2a1c8e95ccb58796c5e to your computer and use it in GitHub Desktop.
create dummy images using node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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