Created
February 9, 2019 01:25
-
-
Save slmcmahon/42563d907620d087dd9859c5d237f690 to your computer and use it in GitHub Desktop.
JIMP example
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
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