• QR.js JS 生成 PNG二维码图片,使用说明


    QR.js JS 生成 PNG二维码图片,使用说明

    github 上的原文什么都没有提,我给 fork 了一个,并添加了使用说明
    https://github.com/KyleBing/qr.js

    一、使用说明

    1. Browser 模式

    html 中引入 qr.js

    <script src="qr.js">script>
    
    • 1

    生成 png 图片

    let linkAddress = 'https://kylebing.cn'
    let qrCodeData = QRCode.generatePNG(linkAddress)
    document.querySelector('.qr-code').setAttribute('src', qrCodeData)
    
    • 1
    • 2
    • 3

    2. Vue 模式

    Vue

    <img :src="shareQrCode" alt="qr">
    
    • 1
    let linkAddress = 'https://kylebing.cn'
    this.shareQrCode = QRCode.generatePNG(linkAddress)
    
    • 1
    • 2

    二、 option 说明

    参数可选参数类型可能的值说明
    version可选Number-1, 1 ~ 40版本,当为 -1 时,使用可能的最小值
    mode可选Stringnumeric, alphanumeric, octet默认使用最小的值
    ecclevel可选StringL M Q H默认值 L

    generateHTML generatePNG

    参数可选参数类型可能的值说明
    modulesize可选NumberNumber每个方块的大小,默认为 5px
    margin可选NumberNumber边框距离,默认为 4px

    原文说明

    // the public interface is trivial; the options available are as follows:
    //
    // - version: an integer in [1,40]. when omitted (or -1) the smallest possible
    //   version is chosen.
    // - mode: one of 'numeric', 'alphanumeric', 'octet'. when omitted the smallest
    //   possible mode is chosen.
    // - ecclevel: one of 'L', 'M', 'Q', 'H'. defaults to 'L'.
    // - mask: an integer in [0,7]. when omitted (or -1) the best mask is chosen.
    //
    // for generate{HTML,PNG}:
    //
    // - modulesize: a number. this is a size of each modules in pixels, and
    //   defaults to 5px.
    // - margin: a number. this is a size of margin in *modules*, and defaults to
    //   4 (white modules). the specficiation mandates the margin no less than 4
    //   modules, so it is better not to alter this value unless you know what
    //   you're doing.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    以下是原仓库 Readme:

    qr.js: QR code generator in pure Javascript (2011)

    This is a fairly standalone script for producing QR code on the fly.
    Originally developed for my own interest, the code is fully commented and well-structured.
    The code is in the public domain (or to be exact, Creative Commons Zero),
    and you can use it for absolutely any purpose.

    See also a node.js module based on qr.js, packaged by Nadav Ivgi.

  • 相关阅读:
    LeetCode题目笔记——1710. 卡车上的最大单元数
    线性代数学习笔记7-5:复习——正交、投影、行列式、特征值
    Android服务器的通信方式
    Docker Compose安装
    flex_dashboard
    Trie字典树
    国科大体系结构习题 | 第二章 计算机系统结构基础
    想考【软考高级】,但不具备计算机基础?“系规”适合你
    【博学谷学习记录】超强总结,用心分享|架构师-Netty核心组件
    Android开发对压缩文件的处理
  • 原文地址:https://blog.csdn.net/KimBing/article/details/126539852