-
-
Save ZucchiniZe/1713e3532578881f0ef3 to your computer and use it in GitHub Desktop.
hook.io image hook for manipulating images using ImageMagick
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
/* | |
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