Created
July 26, 2014 13:15
-
-
Save singuerinc/994d413e41cdeace4766 to your computer and use it in GitHub Desktop.
Batch image generation with Node.js
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
var fs = require('fs'), | |
fabric = require('fabric').fabric, | |
async = require('async'); | |
var names = ["Coleman", "Simon", ...]; | |
async.eachSeries(names, function(name, callback) { | |
var path = __dirname + '/images/' + name.toLowerCase() + '.png'; | |
var out = fs.createWriteStream(path); | |
var canvas = fabric.createCanvasForNode(300, 200); | |
var text = new fabric.Text(name, { | |
fontFamily: 'Christopherhand', | |
fontSize: 60, | |
fill: '#FF0000', | |
left: 0, | |
top: 0 | |
}); | |
canvas.add(text); | |
var stream = canvas.createPNGStream(); | |
stream.on('data', function(chunk) { | |
out.write(chunk); | |
}); | |
stream.on('end', function() { | |
callback() | |
}); | |
}, function(err) { | |
console.log('done!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment