js 生成二维码图片

1.用纯JavaScript实现的微信二维码图片生成器

QRCode.js是javascript实现二维码(QRCode)制作生成库。 QRCode.js有着良好的跨浏览器兼容性(高版本使用HTML5的 Canvas,低版本IE使用table元素绘制),而且QRCode.js没有任何依赖。只需要引用一个JS。

兼容: 几乎支持所有浏览器: IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile

项目地址: http://davidshimjs.github.io/qrcodejs/

github 地址: https://github.com/davidshimjs/qrcodejs

// 基本使用, 首先需要添加对qrcode.js的引用,并创建一个空DIV

<script>
new QRCode(document.getElementById("qrcode"), "http://www.ssports.com/");
</script>

// 更多参数可以选

var qrcode = new QRCode("test", {
    text: "http://jindo.dev.naver.com/collie",
     128,
    height: 128,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

// 你可以动态地改变二维码图片

<script>
qrcode.clear();
qrcode.makeCode("http://naver.com");
</script>

2.SVG矢量图用来生成二维码图片

JsBarcode 是一个生成条形码的开源库支持的有: CODE128 CODE128 (自动模式切换) CODE128 A/B/C (强制模式)等,在现代流量器上它会生成一个SVG矢量图用来生成条形码,使用如下

项目主页: https://github.com/lindell/JsBarcode

// 基本使用

var JsBarcode = require('jsbarcode');
var Canvas = require("canvas");

var canvas = new Canvas();
JsBarcode(canvas, "Hello");

// Do what you want with the canvas
// See https://github.com/Automattic/node-canvas for more information

3.H5实现的JavaScript扫码库

quaggaJS是由H5实现的JavaScript扫码库,能将条形码扫描成文字,支持静态图片和视频流的扫描。

项目主页 https://github.com/serratus/quaggaJS

// 使用方法

Quagga.init({
    inputStream : {
      name : "Live",
      type : "LiveStream",
      target: document.querySelector('#yourElement')    // Or '#yourElement' (optional)
    },
    decoder : {
      readers : ["code_128_reader"]
    }
  }, function(err) {
      if (err) {
          console.log(err);
          return
      }
      console.log("Initialization finished. Ready to start");
      Quagga.start();
  });

4.这里有一个Server端使用Node.JS生成二维码图片的库,有兴趣的同学也可以研究一下

项目地址: https://github.com/soldair/node-qrcode

原文地址:https://www.cnblogs.com/alantao/p/6512244.html