Created
May 20, 2011 18:07
-
-
Save felixge/983440 to your computer and use it in GitHub Desktop.
On demand image resizing with node.js in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
@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.