Created
August 19, 2020 13:30
-
-
Save M1n007/1f5a17fcff163d95ae064c3c7770717a to your computer and use it in GitHub Desktop.
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
let firstText = 'test'; | |
let secondText = '- aw' | |
const templateChoose = 'urlimage/pathimage' | |
const fontChoose = 'font url/font path' | |
const image = await Jimp.read(templateChoose); | |
const font = await Jimp.loadFont(fontChoose); | |
const w = image.bitmap.width; | |
const h = image.bitmap.height; | |
const textWidth = Jimp.measureText(font, firstText); | |
const textHight = Jimp.measureTextHeight(font, firstText); | |
const imageX = 50; | |
const imageY = h/2 - textHight/2; | |
const textOptions = { | |
text: firstText, | |
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER, | |
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE | |
}; | |
const secondTextOptions = { | |
text: secondText, | |
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER, | |
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE | |
}; | |
// image.resize(1080,1080); | |
image.print(font, imageX, imageY, textOptions, 1000,textHight); | |
image.print(font, imageX, imageY + 80, secondTextOptions, 1000,textHight); | |
image.writeAsync('./quotes1.png'); | |
// const imageBase64 = await image.getBase64Async(Jimp.MIME_PNG); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment