Last active
September 14, 2018 17:50
-
-
Save whisher/c542adabfe562d55435e5b56e23a208f 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
| const createGallery = (imageName) => { | |
| const prefix = 'gallery_'; | |
| const imagePath = './images/'; | |
| const readableStream = fs.createReadStream(imagePath + imageName); | |
| const writableStream = fs.createWriteStream(imagePath + prefix + imageName); | |
| const transformer = sharp() | |
| .resize(1110, 600) | |
| .crop(sharp.strategy.entropy) | |
| .on('error', function(err) { | |
| console.log('sharp ', err); | |
| }); | |
| pump(readableStream, transformer, writableStream, function(err) { | |
| if (err) { | |
| console.log('pipe sharp finished', err); | |
| } | |
| }); | |
| return prefix + imageName; | |
| }; | |
| exports.gallery = (req, res, next) => { | |
| const url = getUrl(req); | |
| const imageName = createGallery(req.file.filename); | |
| const imagePath = url + '/images/' + imageName; | |
| const src = imagePath; | |
| const name = req.file.originalname; | |
| const data = {src: src, name: name}; | |
| // Hack | |
| setInterval(function() { | |
| res.status(200).json(data); | |
| }, 1000); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.