如何在飞行中调整图像大小(快递和S3)

时间:2016-08-03 12:19:10

标签: node.js express amazon-s3 image-resizing

我想从网址获取图片,然后在不保存的情况下立即调整大小

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)

我现在可以使用request lib返回相同的图片但是我如何操作它然后作为响应返回?

1 个答案:

答案 0 :(得分:6)

有几个npm模块调整一个示例的大小是sharp。您可以通过这种方式使用它(例如,从API文档中获取)。

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

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

readableStream将是原始图片的流。

相关问题