0

I have uploaded photo.jpg to C:/myapp/public/fullsize. I want to resize this image and put it in C:/myapp/public/thumb. I do not know how to get newPath and thumbPath

 C:/myapp/
             server.js
             app/
                 myscript.js
             public/
                 fullsize/
                         photo.jpg
                 thumb/

In myscript.js

 var path = require('path');
 var im = require('imagemagick');
 var imageName = path.basename(req.files.file.path); //photo.jpg
    var newPath =  ???;
    var thumbPath = ???;
    im.resize({
                  srcPath: newPath,
                  dstPath: thumbPath,
                  width:   200
                }, function(err, stdout, stderr){
                  if (err) throw err;
                  console.log('resized image to fit within 200x200px');
                });
user3044147
  • 1,374
  • 5
  • 14
  • 23

1 Answers1

0

The uploaded files will be located in a temporary location. First you need to move the file to C:/myapp/fullsize. This is explained clearly in this article.

Your next step would be to get req.files.file.name and create destination path. This can be achieved by using

var dstPath = __dirname + "/public/thumb/" + req.files.file.name;

Now you can resize image with the correct paths.