Skip to content

Instantly share code, notes, and snippets.

@Marak
Last active July 31, 2019 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marak/d20f4de4c0e6dbdf4f3e to your computer and use it in GitHub Desktop.
Save Marak/d20f4de4c0e6dbdf4f3e to your computer and use it in GitHub Desktop.
hook.io example microservice for resizing images
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