node.jsimageexpressuploadimage-compression

How to Compress Image File In Nodejs?


i write a REST API with express and node js and upload image with

multer

and i want resize image before save . for example if a image size is 2MB i want convert less to 1Mb. And I don't want to change the height and width of the photo as well as its extension can you help me?


Solution

  • Try

    https://www.npmjs.com/package/node-image-resizer

    npm i -D node-image-resizer
    
    
    import resizer from 'node-image-resizer';
    
    (async () => {
      await resizer('./image.jpg', setup);
    })();