Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.use('/', (req, res) => {
- const parameters = {
- left: 0.5, //procent wycięcia od góry
- top: 0.2, //procent wycięcia z lewej
- size: 0.5 //szerokość i wysokość zdjęcia brane z szerokości oryginalnego ()
- }
- const fileStream = this.s3.getObject({
- Bucket: '<my-bucket-name>',
- Key: '<photo-key>'
- }).createReadStream();
- let imageInfo;
- const transformer = sharp().on('info', info => {
- imageInfo = info;
- })
- const cropTransformer = sharp().extract({
- left: parameters.left * imageInfo.width,
- top: parameters.top * imageInfo.height,
- width: parameters.size * imageInfo.width,
- height: parameters.size * imageInfo.width
- });
- return fileStream.pipe(transformer).pipe(cropTransformer).pipe(res);
- })
Add Comment
Please, Sign In to add comment