Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
Created February 9, 2019 01:25
Show Gist options
  • Save slmcmahon/42563d907620d087dd9859c5d237f690 to your computer and use it in GitHub Desktop.
Save slmcmahon/42563d907620d087dd9859c5d237f690 to your computer and use it in GitHub Desktop.
JIMP example
const Jimp = require("jimp");
let data = "Dev";
if (process.argv.length > 2) {
data = process.argv[2];
}
var fileName = 'ic_launcher.png';
var imageCaption = `[${data}]`;
var loadedImage;
Jimp.read(fileName)
.then(function (image) {
loadedImage = image;
return Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
})
.then(function (font) {
let maxWidth = loadedImage.bitmap.width;
let maxHeight = loadedImage.bitmap.height;
loadedImage.print(font, 0, 0,
{
text: imageCaption,
alignmentX: Jimp.HORIZONTAL_ALIGN_CENTER,
alignmentY: Jimp.VERTICAL_ALIGN_MIDDLE
},
maxWidth,
maxHeight).write(fileName);
})
.catch(function (err) {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment