text2png('Create png image\nfrom multi-line text!');
$ npm install text2png
var fs = require('fs');
var text2png = require('text2png');
fs.writeFileSync('out.png', text2png('Hello!', {textColor: 'blue'}));
text2png depends on node-canvas.
See node-canvas wiki on installing node-canvas.
text2png(text, option)
param | default |
---|---|
text | (required) |
option.font | '30px sans-serif' |
option.textColor | 'black' |
option.bgColor | null |
option.lineSpacing | 0 |
option.xpadding | 0 |
option.ypadding | 0 |
option.output | 'buffer' |
option.output = 'buffer' | 'stream' | 'dataURL' | 'canvas'
'canvas'
returns node-canvas object.
text2png('Example\nText', {
font: '80px Futura',
textColor: 'teal',
bgColor: 'linen',
lineSpacing: 10,
xpadding: 20,
ypadding: 20
});
Enjoy!