wordwrapimagewriter
ES6 JS class to write text onto image with word wrapping
Installation
npm install wordwrapimagewriter --save
Usage
Write lines onto an image wrapping and automatically determining
spacing and padding as specified
var writer = new wordwrapimagewriter({
imgFilename: './imageToWriteOnto.png',
availableLines: 3,
topPadPx: 50,
lineBottomPadPx: 5,
fontFile: './HelveticaBold.ttf',
});
writer.openImg(() => {
var usernameColor = writer.img.colorAllocateAlpha(255, 20, 20, 1);
var textColor = writer.img.colorAllocateAlpha(255, 255, 255, 1);
var usernameText = "jenk37: ";
var messageText = "I think that the wordwrapimagewriter is pretty good";
var textThatWontFit = writer.writeText(usernameText, usernameColor);
if (textThatWontFit) {
console.log("[!] Text couldn't fit:", textThatWontFit);
}
writer.setFontSize(30);
writer.setFont('./Helvetica.ttf');
textThatWontFit = writer.writeText(messageText, textColor);
if (textThatWontFit) {
console.log("[!] Text couldn't fit:", textThatWontFit);
}
writer.save("./newImageFilename.png", () => {
return callback();
});
});
Credits
http://c-cfalcon.rhcloud.com