Skip to content

Instantly share code, notes, and snippets.

@ZucchiniZe
Forked from Marak/image.js
Created November 23, 2014 04:42
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 ZucchiniZe/1713e3532578881f0ef3 to your computer and use it in GitHub Desktop.
Save ZucchiniZe/1713e3532578881f0ef3 to your computer and use it in GitHub Desktop.
hook.io image hook for manipulating images using ImageMagick
/*
http://hook.io/ZucchiniZe/image
*/
var gm = require('gm');
module['exports'] = function image (hook, callback) {
var imageReadStream;
hook.debug('Opening read stream to image: ' + hook.params.image);
if (hook.streaming) {
readStream = hook.req;
}
else if (hook.params.image && hook.params.image._readableState.buffer.length > 0) {
imageReadStream = hook.params.image;
} else {
imageReadStream = hook.open(hook.params.url);
}
hook.debug('Opening write stream to blur transform');
var blur = hook.post('http://hook.io/Marak/image/blur?x=' + hook.params.x);
hook.debug('Writing response headers');
hook.res.writeHead(200, { 'Content-Type': 'image/png' });
hook.debug('Piping source image through transform streams');
imageReadStream
.pipe(blur)
};
module['exports'].schema = {
"url": {
"type": "string",
"default": "http://hook.io/img/logo.png"
},
"image": {
"type": "file"
},
"x": {
"type": "number",
"default": 2
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment