Skip to content

Instantly share code, notes, and snippets.

@rhlc
Created November 4, 2022 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhlc/b57d81e4a6d9b71570aaa4f50ed7cc62 to your computer and use it in GitHub Desktop.
Save rhlc/b57d81e4a6d9b71570aaa4f50ed7cc62 to your computer and use it in GitHub Desktop.
Add Text Over Image (Using jimp)
// to convert ttf font to fnt use http://www.angelcode.com/products/bmfont/
var Jimp = require("jimp");
const alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
const func = async (alphabet) => {
const font = await Jimp.loadFont('font/roboto-slab.fnt');
Jimp.read("base.png", (err, image) => {
if (err) throw err;
image
.print(
font,
x = 0,
y = 0,
{
text: alphabet,
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE,
},
maxWidth = 300,
maxHeight = 300
)
.write(`output/${alphabet}.png`); // save
});
};
alphabet.forEach(char => {
func(char);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment