问题
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