Skip to content

Instantly share code, notes, and snippets.

@taylorstine
Created March 11, 2017 12:57
Show Gist options
  • Save taylorstine/469cffedf788e9ec7c4740ed7b6f7a8c to your computer and use it in GitHub Desktop.
Save taylorstine/469cffedf788e9ec7c4740ed7b6f7a8c to your computer and use it in GitHub Desktop.
Requests an image as a buffer and resizes it.
//request is the module we'll be using to make network calls.
//https://github.com/request/request
import request from "request"
import sharp from 'sharp'
function requestImage(imageUrl) {
//add encoding:null to make sure we get a buffer instead of a string in body
request({url: imageUrl, encoding:null}, (err, response, body)=>{
const theImage = body;
const resizedImage = sharp(theImage)
.resize(500, 500)
.max()
.toBuffer();
//send the image
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment