Last active
July 31, 2019 19:04
-
-
Save Marak/d20f4de4c0e6dbdf4f3e to your computer and use it in GitHub Desktop.
hook.io example microservice for resizing images
This file contains hidden or 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
module['exports'] = function imageResize (hook, callback) { | |
// GraphicsMagick fully supported | |
var gm = require('gm'); | |
// for a more complete example that supports file uploads and streaming uploads | |
// see: http://image.resize.hook.io | |
// grab an image as a url | |
// no file has been uploaded, fallback to the image "url" parameter | |
var stream = hook.open('https://hook.io/img/robotcat.png'); | |
hook.res.writeHead(200, { 'Content-Type': 'image/png' }); | |
gm(stream) | |
.options({imageMagick: true }) | |
.resize(150, 150) | |
.stream() | |
.pipe(hook.res); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment