Skip to content

Instantly share code, notes, and snippets.

@felixge
Created May 20, 2011 18:07
Show Gist options
  • Save felixge/983440 to your computer and use it in GitHub Desktop.
Save felixge/983440 to your computer and use it in GitHub Desktop.
On demand image resizing with node.js in
// Usage: http://localhost:8080/image.jpg/100x50
var http = require('http');
var spawn = require('child_process').spawn;
http.createServer(function(req, res) {
var params = req.url.split('/');
var convert = spawn('convert', [params[1], '-resize', params[2], '-']);
res.writeHead(200, {'Content-Type': 'image/jpeg'});
convert.stdout.pipe(res);
}).listen(8080);
// If you like this, consider attending our Node.js Workshop on June 10th in Cologne:
// http://nodecologne.eventbrite.com/
@felixge
Copy link
Author

felixge commented May 20, 2011

@tylerbenson Sure you would certainly want to have some validation in there if you want to use this in production : ). But @Qard is right, I'd be impressed if you can exploit this.

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