app.post('/upload',
function (req, res) {
var
tempPath = req.files.file.path,
name = '',
targetPath = '';
fileExist = true;
fileNumber = 0;
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.