How to resize image in Node js

前端 未结 3 1211
灰色年华
灰色年华 2020-12-20 08:10

I need to resize my images before I upload them to s3 (amazon). I tried this function but it\'s not working.

Here is the function that uploads the image.

My

3条回答
  •  执笔经年
    2020-12-20 08:34

    In your example you're saving the image to S3 (s3.putObject) before resizing it (im.resize). Move the resize function before the put.

    You're also not passing the image to the resize function; you'll need something like

    im.resize(fileStream, { // pass in the image
          height:100,
          width:   200
     }, function(err, stdout, stderr){
          if (err) throw err;
          console.log('resized image to fit within 200x200px');
     });
    

    Check the docs for the library you're using for the correct syntax.

提交回复
热议问题