2014-09-23 36 views
0

任何人告訴我如何使用NodeJs模塊'gm'獲取圖像信息。在這裏我使用下面的代碼重新調整大小。但如果圖像小於重新調整大小比不重新調整大小,那麼我想驗證圖像的寬度和高度,以便達到目的我想獲取圖像信息。NodeJS gm模型用於獲取圖像的信息?

gm(main_url_path) 
.resize(size, size) 
.write(compress_path, function (err){ 
    if(!err){ 
     callback(compress_path); 
    }else{ 
     console.log("Not Compressed success !!"+err); 
     callback(null); 
    } 
}); 

回答

2
// output all available image properties 
gm('/path/to/img.png') 
.identify(function (err, data) { 
    if (!err) console.log(data) 
}); 

編輯

如果你想知道包的NodeJS基本實現,參觀故宮的網站,因爲它通常提供的包內的基本功能的例子:https://www.npmjs.org/package/gm