Skip to content

Instantly share code, notes, and snippets.

@M1n007
Created August 19, 2020 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M1n007/1f5a17fcff163d95ae064c3c7770717a to your computer and use it in GitHub Desktop.
Save M1n007/1f5a17fcff163d95ae064c3c7770717a to your computer and use it in GitHub Desktop.
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