2

I'm working on a Node.js application and I'm facing a critical problem right now which it is Resizing img after uploading .. the thing is everything goes right starting from uploading to getting the path of the uploaded img but I can't understand why this is happening .. here's my code and the error

  var fileName = req.file.filename;
  var filpath = "/uploads/" + fileName;

  gm(filpath)
  .resize(240, 240)
  .write('/uploads/'+'resized-'+fileName, function (err) {
    if (err) console.log(err);
    else console.log("HOOLA");
  });

The error is

{ [Error: Command failed: Invalid Parameter - /uploaded_file-1474832730810.png
] code: 4, signal: null }

The log enter image description here

UPDATE: first of all I would like to thank @r-a-lucas,and here's the full answer for Windows users:

  1. npm install gm --save
  2. download the latest ImageMagick from here ImageMagic EXE
  3. Make sure it is excusable (advance system settings -> Advance -> Environment Variables -> add Path most likely in C:\Program Files\ImageMagick-*** )
  4. In your JS file make sure to add (__dirname) to get the full path of the img. gm(__dirname+filpath)
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
developerbh
  • 180
  • 10

1 Answers1

3

It looks like you may need to install imagemagick for Windows. Check out this answer here: imagemagick with nodejs not working. Hopefully that helps. Best.

Community
  • 1
  • 1
R.A. Lucas
  • 1,121
  • 1
  • 12
  • 17
  • already installed `ABC@DESKTOP-VKM06U6 MINGW32 ~/Desktop/Node.js/sales app $ npm install ImageMagick --save imagemagick@0.1.3 node_modules\imagemagick` – developerbh Sep 25 '16 at 20:32
  • Yes, this is beyond doing just the `npm install` but that you may need to install the imagemagick.exe and make sure that the executable is in the path. – R.A. Lucas Sep 25 '16 at 20:37
  • definitely you are right .. can't thank you enough bro .. gonna update the full answer now :D – developerbh Sep 25 '16 at 20:47
  • Take care that another convert.exe can be under C:\Windows\System32\convert.exe. I have it on my Windows 10, and it is the selected one from the PATH. – bvamos Jul 15 '21 at 11:08