Created
November 4, 2022 05:53
-
-
Save rhlc/b57d81e4a6d9b71570aaa4f50ed7cc62 to your computer and use it in GitHub Desktop.
Add Text Over Image (Using jimp)
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
// 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