Skip to content

Instantly share code, notes, and snippets.

@singuerinc
Created July 26, 2014 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save singuerinc/994d413e41cdeace4766 to your computer and use it in GitHub Desktop.
Save singuerinc/994d413e41cdeace4766 to your computer and use it in GitHub Desktop.
Batch image generation with Node.js
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