Search code examples
javascriptnode.jsmulter

Is there any option to reduce the image size and resize the image in nodejs with multer functionality?


var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, '/tmp/my-uploads')
  },
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now())
  }
})

var upload = multer({ storage: storage })

I need to resize the image and compress the image size to lowest and upload into the directory.Any help?


Solution

  • This can be done using multer-imager npm module.

    http://www.npmjs.com/package/multer-imager

    make sure you install graphicsmagick before that(not npm module). Click on the link below to install graphicsmagick.

    http://linuxg.net/how-to-install-graphicsmagick-1-3-18-on-ubuntu-13-10-13-04-12-10-12-04-linux-mint-16-15-14-13-pear-os-8-7-and-elementary-os-0-2/

    Then install multer-imager and gm npm module.