node 解析图片二维码的内容

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);
		
		
	});
	
})

  

转载于:https://www.cnblogs.com/muamaker/p/10094905.html

你可能感兴趣的:(javascript,ViewUI)