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 }
UPDATE: first of all I would like to thank @r-a-lucas,and here's the full answer for Windows users:
- npm install gm --save
- download the latest ImageMagick from here ImageMagic EXE
- Make sure it is excusable (advance system settings -> Advance -> Environment Variables -> add Path most likely in C:\Program Files\ImageMagick-*** )
- In your JS file make sure to add (__dirname) to get the full path of the img.
gm(__dirname+filpath)