Use gm to read the image, the path is correct,
Error report: gm convert unable to open file ...[NO such file or directory]
router.js
//path.join(__dirname,'../avatar/',filename)等價于
==c:\users\MrsH\Desktop\codeth\shuoshuo\router\avatar\uestcw.jpg
所以路徑是沒有問題,圖片存在可以無法讀取并修改
gm(path.join(__dirname, '../avatar/', filename))
.crop(w,h,x,y)
.resize(100,100,"!")
.write(path.join(__dirname, './avatar/', filename),function(err){
if(err){
console.log(err)
res.send("-1");
return;
}
res.send("1");
});
The following is the document tree
Following the voice in heart.
//寫成這樣沒錯
gm(path.join(__dirname,'../models','pic08.jpg'))
.crop(100,100,100,100)
.resize(50,50,'!')
.write('./a.jpg', (err)=>{
if(err) console.log(err);
console.log('finished');
})
//當(dāng)我把write的路徑改為以下時,報錯
path.join(__dirname,'./models','pic08.jpg')
//改成這樣是對的
path.join(__dirname,'models','pic08.jpg')
So when path.join is used in the future, it means that files in the current directory should not be added ./