Created
October 2, 2018 11:38
-
-
Save tsh-code/21a22b8e0d7cbc31d3c7a93711ef5209 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
router.post('/:id/title-image', (req, res, next) => { | |
lwip.open(req.file.buffer, 'jpg', (err, image) => { | |
if (err) { next(err); return; } | |
let ratio = (image.width() > 960 ? (960 / image.width()) : 1); | |
image.scale(ratio, (err, image) => { | |
if (err) { next(err); return; } | |
image.crop(image.width(), Math.min((image.width() / 2), image.height()), (err, image) => { | |
if (err) { next(err); return; } | |
image.toBuffer('jpg', { quality: 80 }, (err, buffer) => { | |
if (err) { next(err); return; } | |
db.doc.attachment.write(req.params['id'], "TITLE_IMAGE", buffer, "image/jpeg", (err) => { | |
if (err) { next(err); return; } | |
res.sendStatus(200); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment