我正在使用jimp調整node.js中的圖像大小,我成功地降低了圖像質量,但有點困惑如何得到新的圖像使用jimp調整Node.js中的圖像並獲取新圖像的路徑
Jimp.read("test.jpg", function (err, test) {
if (err) throw err;
test.resize(256, 256)
.quality(50)
.write("new.jpg");
});
我正在使用jimp調整node.js中的圖像大小,我成功地降低了圖像質量,但有點困惑如何得到新的圖像使用jimp調整Node.js中的圖像並獲取新圖像的路徑
Jimp.read("test.jpg", function (err, test) {
if (err) throw err;
test.resize(256, 256)
.quality(50)
.write("new.jpg");
});
更多信息您可以增加圖像的20倍調整性能。只需使用另一個模塊進行圖像處理。檢查了這一點:
https://github.com/ivanoff/images-manipulation-performance
正如你可以看到有,模塊服從跳是最慢的模塊。
嘗試銳利或畫布。
我使用app-root-path
NPM獲得ROOTPATH:
var appRoot = require('app-root-path');
var imgName = new Date().getTime().toString();
var savePath = appRoot + '/uploads/' + imgName;
Jimp.read("test.jpg", function (err, image) {
if (err) throw err;
image.resize(256, 256)
.quality(50)
.write(savePath);
// save savePath to database
});
讀取DOC(https://github.com/oliver-moran/jimp#writing-to-files-and-buffers)告訴我,你可以在'write'函數中指定絕對路徑 – 0aslam0