Skip to content

Instantly share code, notes, and snippets.

@Marak
Last active August 29, 2015 14:08
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 Marak/d7824025363975d16f5d to your computer and use it in GitHub Desktop.
Save Marak/d7824025363975d16f5d to your computer and use it in GitHub Desktop.
Resize a remote image
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