The method of using the two-dimensional code content identifying nodejs

const decodeImage = require('jimp').read;
const qrcodeReader = require('qrcode-reader');
qrDecode("123.png",function(data){
    console.log(data);
});
function qrDecode(data,callback){
    decodeImage(data,function(err,image){
        if(err){
            callback(false);
            return;
        }
        let decodeQR = new qrcodeReader();
        decodeQR.callback = function(errorWhenDecodeQR, result) {
            if (errorWhenDecodeQR) {
                callback(false);
                return;
            }
            if (!result){
                callback(false);
                return;
            }else{
                callback(result.result)
            }
        };
        decodeQR.decode(image.bitmap);
    });
}

Download and introducing jimp, qrcode-reader two modules can be realized.

Guess you like

Origin www.cnblogs.com/teamemory/p/12075998.html