Hi all, I’m creating a little node.js app (for test) that get image from a 
FORM, save it in a directory and create a thumbnail version. 
Form and upload works with no problem, but I can not create the thumbnail. 
This is my code: 

app.post('/upload', function (req, res) {
    var tempPath = req.files.file.path,
        name = '',
        targetPath = '';
    
    fileExist = true; 
    fileNumber = 0;
    
    var fileType = path.extname(req.files.file.name);
    var fileName = path.basename(req.files.file.name,fileType);

    while (fileExist) {
  
      fileNumber_str = fileNumber.toString(); 
  
      var current = fileName + "_" +fileNumber_str + fileType;
      console.log("Controllo per "+current);
  
      if (fs.existsSync(__dirname + "/images/orig/" + current)) {
          console.log("--> Esiste");
          fileNumber++;
      } else {
          var newPath = __dirname + "/images/orig/" + current;
          console.log("nuovo nome : "+newPath);
          fs.rename(tempPath, newPath, function(err) {
                if (err) throw err;
                //Ora creo il thumb
                var newPathT = __dirname + "/images/thumb/" + current;
                gd.openPng([newPath],function(png,path){
                     if(png) {
                        var w = Math.floor(png.width/2), h = 
Math.floor(png.height/2);
                        var target_png = gd.createTrueColor(w, h);
                  
                        
png.copyResampled(target_png,0,0,0,0,w,h,png.width,png.height);
                        target_png.savePng(newPathT, 1, gd.noop);
                     }
                     else {
                       console.log("no png");
                       console.log(png);
                       console.log(path); 
                     }
                });
                console.log("Upload completed!");
            });

  
          break;
      }
    }
    
    res.redirect("/");
res.end();    
});


The function gd.open(…) set always “png” variables to “undefined”. I don’t 
understand where is my error. 

Thanks in advance and sorry for my bad english.

M.

-- 
Michel 'ZioBudda' Morelli                       [email protected]
Sviluppo applicazioni CMS DRUPAL e web dinamiche (LAMP+Ajax)
Telefono: 0200619074
Mobile: +39-3939890025 --  Fax: +39-0291390660

http://www.ziobudda.net                         Skype: zio_budda
http://www.ziobuddalabs.it                     Twitter: ziobudda

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to