Created
September 17, 2018 15:39
-
-
Save whisher/2adf4f51d611cd727a25dbf405de1680 to your computer and use it in GitHub Desktop.
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
| exports.gallery = (req, res, next) => { | |
| const imagePath = './images/'; | |
| const sizes = [200, 800]; | |
| const image = `${imagePath}${req.file.filename}`; | |
| const ext = path.extname(image); | |
| const filename = path.basename(image, ext); | |
| const resize = size => sharp(`${image}`) | |
| .resize(size, size) | |
| .toFile(`${imagePath}${filename}-${size}${ext}`); | |
| Promise | |
| .all(sizes.map(resize)) | |
| .then(metadata => { | |
| return metadata; | |
| }) | |
| .then(metadata => { | |
| const url = getUrl(req); | |
| const src = url + '/images/' + `${filename}-${sizes[0]}${ext}`; | |
| const data = {src: src, name: filename}; | |
| res.status(200).json(data); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment