QRCode only through the front-end can generate two-dimensional code and parsing two-dimensional code image,
First of all to introduce file Qrcode.js, as: http://static.runoob.com/download/qrcodejs-04f46c6.zip;
1. Identify local images:
Through the form of a file to get to the local picture, generate a temporary path to the picture, and then parse the two-dimensional code image;
The Qrcode.decode (IMG) method can parse the two-dimensional code image and return the parsed image to the text value via Qrcode.callback=function (IMG) {};
Get preview picture path var getobjecturl = function (file) { var url = null; if (window.createobjecturl!=undefined) {//basic URL = window.createobjecturl (file); } else if (window. url!=undefined) {//Mozilla (firefox) url = window. Url.createobjecturl (file); } else if (window.webkiturl!=undefined) {//WebKit or chrome URL = window.webkitURL.createObjectURL (file); } return URL; } Console.log (Getobjecturl (newfile[0]));//newfile[0] is a QR code image file uploaded via input files qrcode.decode (Getobjecturl ( Newfile[0])); Qrcode.callback = function (imgmsg) { console.log ("Imgmsg", imgmsg); }
2, generate two-dimensional code:
var qrcode = new QRCode (document.getElementById ("QRCode"), {
WIDTH:100,
height:100
});
Qrcode.makecode (' 123123 ');
Generate two-dimensional code
Qrcode.js identification and parsing of two-dimensional code images and generation of two-dimensional code images