• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1QR Code generator library
2=========================
3
4
5Introduction
6------------
7
8This project aims to be the best, clearest QR Code generator library in multiple languages. The primary goals are flexible options and absolute correctness. Secondary goals are compact implementation size and good documentation comments.
9
10Home page with live JavaScript demo, extensive descriptions, and competitor comparisons: [https://www.nayuki.io/page/qr-code-generator-library](https://www.nayuki.io/page/qr-code-generator-library)
11
12
13Features
14--------
15
16Core features:
17
18* Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/JavaScript, Python, Rust, C++, C
19* Significantly shorter code but more documentation comments compared to competing libraries
20* Supports encoding all 40 versions (sizes) and all 4 error correction levels, as per the QR Code Model 2 standard
21* Output format: Raw modules/pixels of the QR symbol
22* Detects finder-like penalty patterns more accurately than other implementations
23* Encodes numeric and special-alphanumeric text in less space than general text
24* Open-source code under the permissive MIT License
25
26Manual parameters:
27
28* User can specify minimum and maximum version numbers allowed, then library will automatically choose smallest version in the range that fits the data
29* User can specify mask pattern manually, otherwise library will automatically evaluate all 8 masks and select the optimal one
30* User can specify absolute error correction level, or allow the library to boost it if it doesn't increase the version number
31* User can create a list of data segments manually and add ECI segments
32
33Optional advanced features (Java only):
34
35* Encodes Japanese Unicode text in kanji mode to save a lot of space compared to UTF-8 bytes
36* Computes optimal segment mode switching for text with mixed numeric/alphanumeric/general/kanji parts
37
38More information about QR Code technology and this library's design can be found on the project home page.
39
40
41Examples
42--------
43
44The code below is in Java, but the other language ports are designed with essentially the same API naming and behavior.
45
46```java
47import java.awt.image.BufferedImage;
48import java.io.File;
49import java.util.List;
50import javax.imageio.ImageIO;
51import io.nayuki.qrcodegen.*;
52
53// Simple operation
54QrCode qr0 = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
55BufferedImage img = toImage(qr0, 4, 10);  // See QrCodeGeneratorDemo
56ImageIO.write(img, "png", new File("qr-code.png"));
57
58// Manual operation
59List<QrSegment> segs = QrSegment.makeSegments("3141592653589793238462643383");
60QrCode qr1 = QrCode.encodeSegments(segs, QrCode.Ecc.HIGH, 5, 5, 2, false);
61for (int y = 0; y < qr1.size; y++) {
62    for (int x = 0; x < qr1.size; x++) {
63        (... paint qr1.getModule(x, y) ...)
64    }
65}
66```
67
68
69License
70-------
71
72Copyright © 2022 Project Nayuki. (MIT License)
73[https://www.nayuki.io/page/qr-code-generator-library](https://www.nayuki.io/page/qr-code-generator-library)
74
75Permission is hereby granted, free of charge, to any person obtaining a copy of
76this software and associated documentation files (the "Software"), to deal in
77the Software without restriction, including without limitation the rights to
78use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
79the Software, and to permit persons to whom the Software is furnished to do so,
80subject to the following conditions:
81
82* The above copyright notice and this permission notice shall be included in
83  all copies or substantial portions of the Software.
84
85* The Software is provided "as is", without warranty of any kind, express or
86  implied, including but not limited to the warranties of merchantability,
87  fitness for a particular purpose and noninfringement. In no event shall the
88  authors or copyright holders be liable for any claim, damages or other
89  liability, whether in an action of contract, tort or otherwise, arising from,
90  out of or in connection with the Software or the use or other dealings in the
91  Software.
92