Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript

Π“Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. 255a118f56f5346b97e56325a1217a16. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-255a118f56f5346b97e56325a1217a16. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° 255a118f56f5346b97e56325a1217a16. Create a QRCode Object.

qrcode(typeNumber, errorCorrectionLevel) => QRCode

Create a QRCode Object.

ParamTypeDescription
typeNumbernumberType number (1

40), or 0 for auto detection.

errorCorrectionLevelstringError correction level (‘L’, ‘M’, ‘Q’, ‘H’)

Encodes a string into an array of number(byte) using any charset. This function is used by internal. Overwrite this function to encode using a multibyte charset.

ParamTypeDescription
sstringstring to encode

addData(data, mode) => void

Add a data to encode.

ParamTypeDescription
datastringstring to encode
modestringMode (‘Numeric’, ‘Alphanumeric’, ‘Byte'(default), ‘Kanji’)

The number of modules(cells) for each orientation. [Note] call make() before this function.

isDark(row, col) => boolean

The module at row and col is dark or not. [Note] call make() before this function.

ParamTypeDescription
rownumber0

createDataURL(cellSize, margin) => string

createImgTag(cellSize, margin, alt) => string

createSvgTag(cellSize, margin) => string

createTableTag(cellSize, margin) => string

createASCII(cellSize, margin) => string

Helper functions for HTML. [Note] call make() before these functions.

ParamTypeDescription
cellSizenumberdefault: 2
marginnumberdefault: cellSize * 4
altstring(optional)
ParamTypeDescription
optsobjectdefault: <>
opts.cellSizenumberdefault: 2
opts.marginnumberdefault: cellSize * 4
opts.scalablebooleandefault: false

renderTo2dContext(context, cellSize) => void

This implementation is based on JIS X 0510:1999.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

10 Best Custom QR Code Generators In JavaScript (2021 Update)

What Is QR Code?

A QR code is a machine-readable image that can be used to store data and information such as text, URL, email and anything you can imagine. Also known as 2-dimensional bar code.

Users can scan QR codes from desktop, image files or using a webcam to quickly read and access the data and information you provide.

The Best QR Code Generator

There are lots of online QR Code Generators out there and You may have realized that it is a tedious task to generates QR codes for each link and then insert them into the page.

Do you want a QR code generator of your own that makes it simple to automatically generate standard or custom QR codes on the modern mobile & web applications?

This is a list of 10 JavaScript/jQuery QR code Generator plugins that help you generate QR codes with custom logos, patterns, styles from any specified content. Enjoy.

Originally Published Oct 28 2019, updated Feb 01 2021

Table of contents:

jQuery QR Code Generators:

WebCodeCam is a jQuery plugin to detect and scan the value of a Barcode or QR code presented in the front of the webcam.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. jQuery Plugin For BarCode QR Code Reader WebCodeCam. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-jQuery Plugin For BarCode QR Code Reader WebCodeCam. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° jQuery Plugin For BarCode QR Code Reader WebCodeCam. Create a QRCode Object.

Qrcode is a tiny jQuery plugin that generates a QR code containing a custom URL, by using qrcdn.com’s jQuery API.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. Creating A QR Code Containing A URL with jQuery qrcode. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-Creating A QR Code Containing A URL with jQuery qrcode. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Creating A QR Code Containing A URL with jQuery qrcode. Create a QRCode Object.

ClassyQR is a very simple jQuery plugin that makes it easy to create QR Codes (Two-dimensional Barcode) from different kinds of data on your website or application.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. jQuery Plugin For Creating QR Codes On Your Website ClassyQR. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-jQuery Plugin For Creating QR Codes On Your Website ClassyQR. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° jQuery Plugin For Creating QR Codes On Your Website ClassyQR. Create a QRCode Object.

A popular QR Code generator that makes uses of JavaScript (jQuery) to render configurable QR Codes in Table or HTML canvas format.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. Canvas Table QR Code Generator. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-Canvas Table QR Code Generator. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Canvas Table QR Code Generator. Create a QRCode Object.

A robust, highly customizable QR code generator which helps you dynamically generate QR codes with custom images (for logos) and labels (for call-to-action text).

Vanilla JS QR Code Generators:

Pure JavaScript QR Code Generator – QRious

QRious is a simple, dependency-free JavaScript library which uses HTML5 canvas to generate QR codes with variable colors, sizes and error correction levels.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. QRious. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-QRious. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° QRious. Create a QRCode Object.

Canvas Based QR Code Generator with Pure JavaScript – VanillaQR.js

VanillaQR.js helps you generate Html5 canvas or HTML table based customizable QR codes in vanilla JavaScript.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. VanillaQR.js. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-VanillaQR.js. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° VanillaQR.js. Create a QRCode Object.

Pretty QR Code Generator With Background Image Support – Awesome-qr.js

Just another QR code generator written in pure JavaScript that helps you generate customizable, pretty-cool QRCode images with support for any background images.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. Awesome qr.js. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-Awesome qr.js. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Awesome qr.js. Create a QRCode Object.

Customizable QR Code Generator In Vanilla JavaScript – qrjs2

qrjs2 is a modified version of the qr.js that lets you generate customizable QR Codes using SVG, PNG and even HTML table element.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. qrjs2 Demo. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-qrjs2 Demo. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° qrjs2 Demo. Create a QRCode Object.

Visual QR Code Generator With Pure JavaScript – Qart.js

Qart.js is a pure JS based visual QR code generator which enables you to merge any images into your QR code. Heavily based on the qrcode library.

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. qart.js. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-qart.js. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° qart.js. Create a QRCode Object.

Conclusion:

Want more jQuery plugins or JavaScript libraries to create awesome QR Code Generators on the web & mobile? Check out the jQuery QR Code and JavaScript QR Code sections.

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Project Nayuki

Introduction

This project aims to be the best, clearest library for generating QR Codes. My primary goals are flexible options and absolute correctness. Secondary goals are compact implementation size and good documentation comments.

This work is an independent implementation based on reading the official ISO specification documents. I believe that my library has a more intuitive API and shorter code length than competing libraries out there. The library is designed first in Java and then ported to TypeScript, Python, Rust, C++, and C. It is open source under the MIT License. For each language, the codebase is roughly 1000 lines of code and has no dependencies other than the respective language’s standard library.

Live demo (JavaScript)

You can generate QR Code symbols conveniently on this web page, powered by the TypeScript version of this library.

Features

Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/ JavaScript, Python, C++, C, Rust

Significantly shorter code but more documentation comments compared to competing libraries (a competitive analysis is provided near the bottom of this page)

Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard

Output format: Raw modules/ pixels of the QR symbol

Detects finder-like penalty patterns more accurately than other implementations

Encodes numeric and special-alphanumeric text in less space than general text

Open-source code under the permissive MIT License

User can specify minimum and maximum version numbers allowed, then library will automatically choose smallest version in the range that fits the data

User can specify mask pattern manually, otherwise library will automatically evaluate all 8 masks and select the optimal one

User can specify absolute error correction level, or allow the library to boost it if it doesn’t increase the version number

User can create a list of data segments manually and add ECI segments (all languages except C)

Optional advanced features (Java only):

Encodes Japanese Unicode text in kanji mode to save a lot of space compared to UTF-8 bytes

Computes optimal segment mode switching for text with mixed numeric/ alphanumeric/ general/ kanji parts

This library is designed with essentially the same API structure and naming in multiple languages for your convenience: Java, TypeScript, Python, Rust, C++ – but a different API in C to avoid dynamic allocation. Regardless of the language used, the generated results are guaranteed to be identical because the algorithms are translated faithfully.

For my own convenience when designing and testing the code, the Java language version of the QR Code generator library is considered to be the master reference version. The TypeScript, Python, Rust, and C++ versions are ported from the Java version, with a balance between writing idiomatic code in the target language but also not deviating too much from the Java version’s design. When in doubt, please consult the Java version to read the more extensive documentation comments and to check what types and values are considered legal.

Java language (SE 7 and above)

Available as a package on The Central Repository: io.nayuki qrcodegen
Online Javadoc documentation: io.nayuki.qrcodegen

This compact, no-dependency library is your one-stop shop for all your QR Code generation needs. To learn how to use the API, please read the demo program’s source code, and maybe skim the library code’s inline Javadoc comments.

For the following practical reasons, Java is my best choice for the reference version because it ensures a high degree of correctness and allows writing detailed documentation comments:

Static type checking prevents dumb typos in names and subtly incorrect arguments being passed (such as byte[] vs. BitBuffer ). (Whereas Python and JavaScript don’t have static type checking.)

There is a strong and clear separation between public interfaces and private implementation details. (Whereas privacy is only a naming convention in Python, and feasible but hacky/ugly in JavaScript.)

Javadoc is expressive and has a consistent syntax. (Whereas Python, JavaScript, and C++ do not have single dominant syntax for documentation comments.)

Java has good standard libraries for file, image, and network handling, and the language is memory-safe. This makes it easier to build a correct application quickly. (Whereas C++ programming easily gets into third-party library frenzy and undefined behavior hell – even though it does have static typing and proper public/ private just like Java.)

Only the Java version of my library contains the advanced segment encoder logic for kanji mode and optimal segment mode switching.

For heavy-duty use, there is a fast version of this Java library. Its speed-up is about 2 to 5 times (see the benchmark timings for both libraries).

TypeScript language

The library: qrcodegen.ts
Demo matching all other languages: qrcodegen-output-demo.ts
The demo on this page: qrcodegen-input-demo.ts

The TypeScript code must be compiled into JavaScript in order to be executed in a web browser, Node.js server, etc. Outputting to ECMAScript 5 is supported, though higher versions are more readable.

This TypeScript library’s high-level organization of classes, public/ private members, and types on variables all resemble Java. The code uses ECMAScript 2015 (ES6) features like classes, let/const, arrow functions, and for-of loops; additionally it uses TypeScript namespaces.

JavaScript language (5 and above)

The JavaScript version of this library can be found in the releases section on GitHub. The code is machine-generated, compiled from TypeScript but with a bit of hand-tweaking of the header. The code is not in the project’s version control tree. These precompiled pieces of JavaScript code are offered in two flavors: ECMAScript 5 compatibility (for Microsoft Internet Explorer 11) or ES6/2015 compatibility (for all modern web browsers).

Historically, I had a hand-written version of this library for ES5. Due to ES5’s lack of classes, the code structure had to be significantly rearranged from the Java version. Then I learned TypeScript, ported the code, and maintained both language versions simultaneously. Later on, I decided to remove the hand-written JavaScript version in favor of compilation from TypeScript – because TS syntax is an easy-to-understand extension of JS, and the TS compiler allows me to use new language features (like ES6) while still being able to compile down to an older version (like ES5).

Python language (3 and above)

Available as a package on PyPI: pip install qrcodegen

Only Python 3 is supported. Please read the demo program’s source code to get a good idea of how to use this library. For further information, consult the big comment at the top of the library source file that summarizes all the public classes, functions, and methods available in the module.

Historically, this library was born as Python 2-and-3 polyglot code. This compatibility was maintained throughout development up to and including version 1.6.0 at commit 71c75cfeb0f0 (2020-03-05). Thereafter, the library removed Python 2 support and now only works on Python 3.

C++ language (11 and above)

The code requires C++11 to compile due to numerous convenient features unavailable in C++03, such as better handling of temporary values and const instance fields. The code is fully portable because it only depends on the C++ standard library but not any OS APIs (e.g. POSIX), and it avoids implementation-dependent assumptions on integer widths. The code completely avoids all undefined behavior (e.g. integer overflow, type punning, etc.).

Unfortunately, the library is unsuitable for embedded microcontroller environments (e.g. Arduino) due to the use of the heavyweight STL std:: vector class and dynamic memory allocation. The C version is the one specifically designed to supported embedded environments.

C language (99 and above)

Notes about this C version of the library:

Many projects choose the C programming language instead of C++, due to simpler semantics, faster compilation, and more robust development tools (debuggers, etc.). This version of the library serves this market.

The other 6 language versions are facsimiles of each other in terms of code architecture, but this C library had to be written from scratch to avoid dynamic memory allocation and to fit C’s object-less programming paradigm.

The code requires a C99-compliant compiler and standard library to compile. Note that older versions of Microsoft Visual C++ (before the 2013 release) only supported C89, which make it more difficult to use my library.

This code is portable and platform-independent by design. It makes no assumptions on endianness, integer type widths, two’s complement, etc. It only relies on behavior mandated by the C standard, for example the fact that int must be at least 16 bits wide.

This C code uses much more low-level indexing and raw buffer passing than the other 6 language versions, so the correctness of the logic is much less obvious at a glance. The safety of this C library was assured in multiple ways: Being mindful of value ranges and choosing suitably sized integer types, designing arithmetic calculations to carefully avoid overflow, running the code under Clang’s UndefinedBehaviorSanitizer and AddressSanitizer and MemorySanitizer, and feeding millions of random inputs then testing for identical output against other language versions.

Here are a photo and video showing the C version of the QR Code generator library running on a PJRC Teensy 3.1 microcontroller. Remember that in the worst case, rendering a version 40 QR Code requires 8 KB of RAM (including temporary scratch space).

Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. teensy qrcodegen thumb. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript Ρ„ΠΎΡ‚ΠΎ. Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript-teensy qrcodegen thumb. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π³Π΅Π½Π΅Ρ€Π°Ρ‚ΠΎΡ€ qr ΠΊΠΎΠ΄Π° javascript. ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° teensy qrcodegen thumb. Create a QRCode Object.

Rust language

The library: lib.rs
Runnable demo program: qrcodegen-demo.rs

Available as a package on Crates.io: qrcodegen
Online documentation at Docs.rs: qrcodegen

Notes about this Rust version of the library:

Has no crate dependencies, only relying on the standard library.

The source code files are laid out in directories according to the Cargo project format.

The higher level text APIs take &str (UTF-8 byte sequence), whereas the lower APIs take &[char] (Unicode code point sequence).

Unlike the language versions which throw exceptions for various conditions, the Rust version panics if an input violates a precondition (e.g. number out of range, character value outside of designated set). However, the encoder functions return Err if the data is too long to fit in a QR Code, because this precondition is quite difficult for a library user to check ahead of time.

Third-party ports

A number of people have translated this library to other programming languages. These third-party libraries vary in their quality and faithfulness to my original work, and are not backed by my personal guarantee.

QR Code technology overview

The QR Code standard defines a method to encode a string of characters or bytes into a grid of dark and light pixels. The text could be numbers, names, URLs, et cetera. Because the standard uses a 2D barcode, it can store much more information than a traditional 1D barcode. To illustrate for comparison, a 1D barcode usually stores 10 to 20 digits, while a QR code often stores 50 textual characters. Note that a QR Code barcode simply represents static data – the barcode does not inherently cause an action to be executed.

Terminology

Some of the frequently used official terminology have non-intuitive meanings, as summarized below:

A popular international standard (symbology), created by Denso Wave, that specifies how messages are converted to barcodes. β€œQR Code” is a registered trademark and wordmark of Denso Wave Incorporated.

A single 2D graphical barcode, which results from the QR Code generation process. Informally this is called a β€œQR code” (without using the word symbol) or a barcode.

A dark or light pixel in a QR Code symbol. Note that a module can be scaled to occupy multiple pixels on a screen or in an image file.

Indicates the revision of the QR Code standard. (The word model here corresponds with the conventional meaning of the word version.) Model 1 QR codes are outdated and essentially never seen. Model 2 QR codes are widespread and dominant. Model 2 also has an extension called Micro QR codes (not implemented in my library). Note that model 1 defines versions 1 through 14, whereas model 2 QR defines versions 1 through 40, allowing much more data capacity.

Generation procedure

The process (and high-level algorithm) for generating a QR Code symbol is as follows:

Choose the text (Unicode string) or binary data (byte string) to encode.

Encode the text into a sequence of zero or more segments. A segment in byte mode can encode any data, but using alphanumeric or numeric mode is more compact if the text falls into these subsets.

Based on the segments to be encoded and the ECL, choose a suitable QR Code version to contain the data, preferably the smallest one.

Concatenate the segments (which have headers and payload) and add a terminator. The result is a sequence of bits.

Add padding bits and bytes to fill the remaining data space (based on the version and ECL).

Reinterpret the bitstream as a sequence of bytes, then divide it into blocks. Compute and append error correction bytes to each block. Interleave bytes from each block to form the final sequence of 8-bit codewords to be drawn.

Initialize a blank square grid based on the version number.

Draw the function patterns (finders, alignment, timing, version info, etc.) onto the appropriate modules. This is formatting overhead to support the QR Code standard, and does not encode any user data.

Draw the sequence of (data + error correction) codewords onto the QR Code symbol, starting from the bottom right. Two columns at a time are used, and the scanning process zigzags going upward and downward. Any module that was drawn for a function pattern is skipped over in this step.

Either manually or automatically choose a mask pattern to apply to the data modules. If masking automatically, then all 8 possibilities are tested and the one with the lowest penalty score is accepted. Note that the format information is redrawn to reflect the mask chosen.

We are now finished the algorithmic parts of QR Code generation. The remaining work is to render the newly generated barcode symbol as a picture on screen, or save it as an image file on disk.

In the context of the steps above, my QR Code generator library provides the logic to perform steps 3 through 11. The other steps must be performed by the user of the library.

Compared to competitors

Relatively compact implementation – 1260 lines of code for the Java version (without QrSegmentAdvanced), 970 lines for TypeScript, 890 lines for Python, 1340 lines for C++, 1280 lines for C, 1270 lines for Rust. (Each version is independent, so it’s meaningless to add up all the line counts.)

The extra advanced features (kanji mode, optimal segment mode switching) in the Java version cost another 290 lines of code and 110 lines of constants

Line counts include the generous amount of comments for functions, comments for blocks of statements, and blank lines – but exclude header comments of author and license info

Contains as few tables of numerical constants as needed – unlike competitors, this implementation does not have tables of: data capacities per version, alignment pattern positions, error correction block sizes, expanded format and version bits, Reed-Solomon divisor polynomials, or finite field exp /log tables

The QR Code and helper objects are all immutable, thus simplifying user operation and reducing errors from accidental misuse of the API

Creates a single segment in numeric, alphanumeric, or byte mode; encodes custom list of segments

The version reviewed was 8f9c1be97466, dated 2021-07-28

About 800 lines of core code in the library

Code is quite concise, minimizing the size of constant tables and avoiding verbose logic

Includes generous comments explaining the overview of behavior

The organization and behavior of subfunctions (such as computing the number of bits and characters, and painting different sets of QR Code modules) are surprisingly similar to my design, despite the fact that he published one year earlier than me and I had never seen his code until months after I published my library

The code is more compact than mine in areas such as the bit buffer and segment encoding, because they are inlined into the QR Code generation workflow instead of being exported as freestanding modules

Creates a single segment in numeric, alphanumeric, or byte mode; cannot encode custom list of segments

The version reviewed was 52f0409a22c5, dated 2015-04-11

About 1200 lines of core code in the library

qr.js: 800 lines for main QR encoding logic, 110 lines for numerical tables, 300 lines for image export; note that generateFrame() is a 400-line monolithic function

Code includes a good number of comments inside and outside functions

Only supports ASCII text and silently corrupts non-ASCII Unicode characters; creates a single segment always in byte mode; cannot encode custom list of segments

The version reviewed was 18decea6ba9a, dated 2015-11-11. The library has since been renamed to QRious

About 1840 lines of core code in the JavaScript library

qrcode.js: 860 lines of code for main QR encoding logic, 340 lines for numerical tables, 360 lines for HTML and GIF output, 280 lines for binary encoding utilities

Contains no comments at all to describe functions; sparsely contains low-level comments to describe chunks of logic statements

The author has ported the library to multiple languages, but with different levels of features. The JavaScript version appears to be the most feature-complete, the Java version has fewer features but more documentation comments, and others have fewer features and comments.

The version reviewed was 94f0023b802a, dated 2016-01-23

About 2900 lines of core code in the library

Supports encoding and decoding QR Code symbols

qrcodedecode.js: 970 lines of code for an encoder with the typical features, 1100 lines for a decoder that can operate on imperfect images (i.e. not axis-aligned with whole-pixel module size), 410 lines for tables of numbers

reedsolomon.js: 420 lines of code for Reed-Solomon encoding, decoding syndrome calculation, error correction, polynomial arithmetic

The version reviewed was b3a77e8f0145, dated 2011-10-15

About 1300 lines of core code in the library

main.py: 420 lines for text accumulation, module drawing, terminal printing

util.py: 550 lines for tables of various constants, QR symbol penalty calculation, segment encoding logic, bit buffer class, block error correction and interleaving, bitstream formatting

base.py: 360 lines for finite field tables, error correction block sizes, polynomial class

Code documentation/ comments are neglectfully sparse in most places, but main.py has some good comments for the public methods of the QRCode class

Creates a single segment in numeric, alphanumeric, or byte mode; creates imperfectly optimized list of segments; encodes custom list of segments

The version reviewed was b79ab5b3e598, dated 2016-03-15

About 2800 lines of core code in the library

builder.py: 900 lines of code for segment encoding, bitstream formatting, ECC generation, module drawing, symbol penalty calculation; 500 lines for export logic to various image formats

__init__.py: 620 lines for mostly character encoding logic, some one-liner wrapper methods for exporting images, and long documentation comments

tables.py: 750 lines of almost entirely numeric constants

Generally speaking the function-level documentation comments are long (and longer than my typical writing), there are comments every 5 or so lines within functions to describe the algorithmic processes (just like I do), but the implementation seems to use a lot of code just to implement basic behaviors

The version reviewed was 467f9a2a3c04, dated 2016-02-26

About 2800 of core code in the library, when the embedded pieces of test and benchmark code are removed

Includes plenty of documentation comments throughout, and at least 200 lines of tables of numbers in ec.rs

Apparently supports encoding Micro QR Codes and kanji mode

The version reviewed was ba77f8bc2d9b, dated 2017-07-18

About 1850 lines of core code in the library, excluding tests

Spends hundreds of lines of code on tables of constants

Code contains few comments, not easy to understand the public API that a developer should use

No penalty calculation or automatic masking

Implements a simple PNG encoder from scratch

The version reviewed was ca9a01fc2f95, dated 2018-06-05

About 2400 lines of code among qr.c/h and reedsol.c/h

Can encode many types of 1D and 2D barcodes, and includes GUI application

Uses heap memory allocation; mutable global variables to store current Reed-Solomon tables (not thread-safe)

Low-density logic in code, not much API documentation comments, 100 lines of QR constants

The version reviewed was 3432bc9aff31, dated 2013-07-09

About 6800 lines of core code in the library

The most popular C library for QR Code encoding by far

Has third-party wrappers for various high-level languages, and numerous patches over the years

Uses dynamic memory allocation, unlike my zero-allocation C library

Supports even more advanced features absent from my library, such as Micro QR codes and structured append mode

Code seems confusing with over 50 public API functions

The version reviewed was 1ef82bd29994, dated 2017-03-15

Π˜ΡΡ‚ΠΎΡ‡Π½ΠΈΠΊ

Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΊΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΉ

Π’Π°Ρˆ адрСс email Π½Π΅ Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠΏΡƒΠ±Π»ΠΈΠΊΠΎΠ²Π°Π½. ΠžΠ±ΡΠ·Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ поля ΠΏΠΎΠΌΠ΅Ρ‡Π΅Π½Ρ‹ *