Flexible Client-side QR Code Generator

Category: Javascript , Recommended | October 14, 2018
Author: nayuki
Views Total: 2,087
Official Page: Go to website
Last Update: October 14, 2018
License: MIT


Flexible Client-side QR Code Generator


Just another flexible, customizable, client-side QR code generator built using pure JavaScript. Also supports Java, Python, and C++.

Main features:

  • Error correction level: Low, Medium, Quartile and High
  • Output format: bitmap or vector
  • Custom scale and border

How to use it:

Import the QR Code Generator’s JavaScript file into the html page.

<script src="qrcodegen.js"></script>

Basic usages:

// Name abbreviated for the sake of these examples here
var QRC = qrcodegen.QrCode;

// Simple operation
var qr0 = QRC.encodeText("Hello, world!", QRC.Ecc.MEDIUM);
var svg = qr0.toSvgString(4);

// Manual operation
var segs = qrcodegen.QrSegment.makeSegments("3141592653589793238462643383");
var qr1 = QRC.encodeSegments(segs, QRC.Ecc.HIGH, 5, 5, 2, false);



  • Tweaked QrCode.drawFormatBits() to use end-exclusive range in second copy for clarity, in most languages.


  • Simplified a bit of JavaScript and TypeScript code.


  • Renamed QrSegment.getBits() to getData() in {Java, JavaScript, TypeScript, Python} code, to match C++ and Rust.


  • Tweaked {JavaScript, TypeScript, HTML} code to encapsulate the application members.


  • Tweaked the BitBuffer class top-level comment in all languages except C.
  • Tweaked BitBuffer.appendBits() comment in several language versions.


  • Swapped {dy,dx} variables in commutative operations for clarity, in all languages.


  • Reformatted some whitespace for alignment in all language versions.


  • Added an assertion to QrCode.encodeSegmentsAdvanced() in all language versions.

Leave a Reply