Hi,

Did you get anywhere with this?  I have a similar problem.

png is set to null when trying to open the image file,

    var projectRootServer="../../../../../server/";
    var source=projectRootServer+"forrest.png";
    var target=projectRootServer+'privateimages/target_image.png';

    var gd = Meteor.npmRequire('node-gd');
    var path = Meteor.npmRequire('path');
    var fs = Meteor.npmRequire('fs');

if (fs.exists(target)) fs.unlink(target);

gd.openPng(source,
function(png, fs) {
   console.log(png)
    if(png) {
     // png is null
    }
}
);



Driving me crazy and now time for bed!

G :)



On Thursday, 13 February 2014 00:59:58 UTC-8, Ziobudda wrote:
>
> 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] 
> <javascript:>
> 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/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/417349df-0669-47df-9582-6267870000c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to