Skip to content

Instantly share code, notes, and snippets.

@thomd
Created February 17, 2015 20:20
Show Gist options
  • Save thomd/5c54eda06ac8ddf331b9 to your computer and use it in GitHub Desktop.
Save thomd/5c54eda06ac8ddf331b9 to your computer and use it in GitHub Desktop.
simple image server
// EXAMPLE
// curl localhost:8080/image.png/400
//
var http = require('http');
var spawn = require('child_process').spawn;
http.createServer(function(req, res) {
var params = req.url.split('/');
var path = __dirname + '/' + params[1];
var size = params[2];
var convert = spawn('convert', [path, '-resize', size, '-']);
res.writeHead(200);
convert.stdout.pipe(res);
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment