Skip to content

Instantly share code, notes, and snippets.

@sessa
Forked from felixge/image_resize.js
Created May 29, 2012 03:28
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 sessa/2822358 to your computer and use it in GitHub Desktop.
Save sessa/2822358 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