Last active
August 29, 2015 14:08
-
-
Save Marak/d7824025363975d16f5d to your computer and use it in GitHub Desktop.
Resize a remote image
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
var gm = require('gm'); | |
module['exports'] = function resizeImage (hook, callback) { | |
hook.debug('Opening image stream'); | |
var readStream = hook.open(hook.params.image); | |
hook.debug('Sending image/png header'); | |
hook.res.writeHead(200, { 'Content-Type': 'image/png' }); | |
gm(readStream) | |
.options({imageMagick: true}) | |
.resize(hook.params.width, hook.params.height) | |
.stream() | |
.pipe(hook.res) | |
}; | |
module['exports'].schema = { | |
"image": { | |
"type": "string", | |
"default": "http://hook.io/img/logo.png" | |
}, | |
"height": { | |
"type": "number", | |
"default": 200 | |
}, | |
"width": { | |
"type": "number", | |
"default": 200 | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment