Skip to content

Instantly share code, notes, and snippets.

@xxx
Forked from felixge/image_resize.js
Created April 6, 2012 02:08
Show Gist options
  • Save xxx/2316017 to your computer and use it in GitHub Desktop.
Save xxx/2316017 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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment