Skip to content

Instantly share code, notes, and snippets.

@mattbaker
Created December 22, 2011 20:41
Show Gist options
  • Save mattbaker/1511774 to your computer and use it in GitHub Desktop.
Save mattbaker/1511774 to your computer and use it in GitHub Desktop.
Send a PNG of a red square to STDOUT using node.js and convert
/* converttest.js: Send a PNG of a red square to STDOUT
* ex. node converttest.js > test.png
*/
var convert = require('child_process').spawn("convert", ["svg:", "png:-"]),
svgsrc = '<svg><rect height="100" width="100" style="fill:red;"/></svg>';
convert.stdout.on('data', function (data) {
process.stdout.write(data);
});
convert.stdin.write(svgsrc);
convert.stdin.end();
@anguyen8
Copy link

It does not work for me on Win7. Most probably because of a bug in the #spawn of Node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment