const {readFile, readFileSync} = require('fs');
const decodeImage = require('jimp').read;
const qrcodeReader = require('qrcode-reader');
const path = require("path");
var p = path.resolve(__dirname,"data/qrcode2.jpg");
readFile(p,function(err,fileBuffer){
if(err){
throw new Error(err);
return ;
}
decodeImage(fileBuffer,function(err,image){
if(err){
throw new Error(err);
return ;
}
let decodeQR = new qrcodeReader();
decodeQR.callback = function(errorWhenDecodeQR, result) {
if (errorWhenDecodeQR) {
throw new Error(errorWhenDecodeQR)
return;
}
if (!result){
console.log("gone with wind");
}else{
console.log(result.result); //结果
}
};
decodeQR.decode(image.bitmap);
});
})