Vladimir Vladimir - 1 year ago 188
Node.js Question

How to resize image on fly(express and S3)

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

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

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

Answer Source

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()
    .on('info', function(info) {
        console.log('Image height is ' + info.height);


the readableStream would be the stream of your original picture.