How to resize image on fly(express and S3)

浪子不回头ぞ 提交于 2021-02-10 06:58:52

问题


I am tring to get image from url and then to resize on fly without saving

var request = require('request');
    request
            .get('s3url')
            .on('response', function (response) {
                console.log(response) // 200
                console.log(response.headers['content-type']) // 'image/png'
            })
            .pipe(res)

I can now return same picture with request lib but how can I manipulate it and then return as response?


回答1:


There are several npm modules that do resizing one example is sharp. You can use it in this way (example taken from the API documentation).

var transformer = sharp()
    .resize(300)
    .on('info', function(info) {
        console.log('Image height is ' + info.height);
    });

readableStream.pipe(transformer).pipe(res);

the readableStream would be the stream of your original picture.



来源:https://stackoverflow.com/questions/38743479/how-to-resize-image-on-flyexpress-and-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!