Created
March 11, 2017 12:57
-
-
Save taylorstine/469cffedf788e9ec7c4740ed7b6f7a8c to your computer and use it in GitHub Desktop.
Requests an image as a buffer and resizes it.
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
//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