Convert Figma logo to code with AI

nayuki logoQR-Code-generator

High-quality QR Code generator library in Java, TypeScript/JavaScript, Python, Rust, C++, C.

5,279
1,118
5,279
3

Top Related Projects

32,747

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

A fast and compact QR Code encoding library

3,701

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.

13,583

Cross-browser QRCode generator for javascript

QR Code Generator implementation in JavaScript, Java and more.

Python QR Code image generator

Quick Overview

The nayuki/QR-Code-generator is a Java library that provides a simple and efficient way to generate QR codes. It supports various customization options, such as setting the size, error correction level, and content of the QR code.

Pros

  • Lightweight and Efficient: The library is lightweight and efficient, making it suitable for a wide range of applications.
  • Customizable: The library offers a variety of customization options, allowing users to create QR codes that fit their specific needs.
  • Cross-platform Compatibility: The Java-based library can be used on multiple platforms, including Windows, macOS, and Linux.
  • Open-source: The project is open-source, allowing developers to contribute to the codebase and customize it as needed.

Cons

  • Limited to Java: The library is written in Java, which may not be the preferred language for all developers.
  • No GUI: The library does not provide a graphical user interface (GUI), which may make it less accessible for some users.
  • Limited Documentation: The project's documentation could be more comprehensive, making it harder for new users to get started.
  • Lack of Active Maintenance: The project appears to have limited active maintenance, with the last commit being over a year ago.

Code Examples

Here are a few examples of how to use the nayuki/QR-Code-generator library:

  1. Generate a Basic QR Code:
QrCode qr = QrCode.encodeText("https://www.example.com", QrCode.Ecc.MEDIUM);
BufferedImage img = qr.toImage(10, 4);
ImageIO.write(img, "png", new File("qrcode.png"));

This code generates a QR code with the content "https://www.example.com" and a medium error correction level, then saves the image to a file named "qrcode.png".

  1. Customize the QR Code:
QrCode qr = QrCode.encodeText("Hello, World!", QrCode.Ecc.HIGH);
qr.setMargin(2);
qr.setColor(0xFF000000, 0xFFFFFFFF);
BufferedImage img = qr.toImage(10, 4);
ImageIO.write(img, "png", new File("custom-qrcode.png"));

This code generates a QR code with the content "Hello, World!" and a high error correction level, sets the margin to 2 modules, and changes the foreground and background colors before saving the image to a file named "custom-qrcode.png".

  1. Encode Binary Data:
byte[] data = {0x01, 0x02, 0x03, 0x04, 0x05};
QrCode qr = QrCode.encodeBinary(data, QrCode.Ecc.LOW);
BufferedImage img = qr.toImage(10, 4);
ImageIO.write(img, "png", new File("binary-qrcode.png"));

This code generates a QR code that encodes the binary data {0x01, 0x02, 0x03, 0x04, 0x05} with a low error correction level, and saves the image to a file named "binary-qrcode.png".

Getting Started

To use the nayuki/QR-Code-generator library, follow these steps:

  1. Add the library to your project's dependencies. If you're using Maven, you can add the following dependency to your pom.xml file:
<dependency>
    <groupId>com.nayuki</groupId>
    <artifactId>qrcode-generator</artifactId>
    <version>1.0.0</version>
</dependency>
  1. Import the necessary classes in your Java code:
import com.nayuki.qrcodegen.QrCode;
import com.nayuki.qrcodegen.QrCode.Ecc;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
  1. Use the

Competitor Comparisons

32,747

ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Pros of ZXing

  • Multi-format support: ZXing can handle various barcode formats beyond QR codes
  • Mature and widely adopted: Used in many production applications
  • Extensive documentation and community support

Cons of ZXing

  • Larger codebase and dependencies: May be overkill for simple QR code generation
  • Steeper learning curve: More complex API due to its multi-format support

Code Comparison

QR-Code-generator (Java):

QrCode qr = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
BufferedImage img = qr.toImage(4, 10);
ImageIO.write(img, "png", new File("qr-code.png"));

ZXing (Java):

QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = writer.encode("Hello, world!", BarcodeFormat.QR_CODE, 200, 200);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
ImageIO.write(image, "PNG", new File("qr-code.png"));

Summary

QR-Code-generator is a lightweight, focused library for QR code generation, while ZXing is a comprehensive barcode processing library. QR-Code-generator is simpler to use for basic QR code tasks, while ZXing offers more flexibility and features at the cost of increased complexity.

A fast and compact QR Code encoding library

Pros of libqrencode

  • More mature and widely used library with extensive documentation
  • Supports a broader range of QR code versions and error correction levels
  • Offers additional features like Micro QR code generation

Cons of libqrencode

  • Written in C, which may be less accessible for some developers
  • Larger codebase and potentially more complex to integrate
  • Slower development and update cycle compared to QR-Code-generator

Code Comparison

QR-Code-generator (C++):

QrCode qr = QrCode::encodeText("Hello, world!", QrCode::Ecc::MEDIUM);

libqrencode (C):

QRcode *qr = QRcode_encodeString("Hello, world!", 0, QR_ECLEVEL_M, QR_MODE_8, 1);

Both libraries offer straightforward APIs for generating QR codes, but QR-Code-generator's C++ interface may be more intuitive for some developers. libqrencode provides more low-level control and options, which can be beneficial for advanced use cases but may require more setup.

QR-Code-generator focuses on simplicity and ease of use, making it a good choice for projects that need basic QR code functionality. libqrencode is better suited for applications requiring more advanced features or fine-grained control over the QR code generation process.

3,701

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.

Pros of jsQR

  • Pure JavaScript implementation, making it easy to use in web browsers
  • Supports QR code detection from images and video streams
  • Lightweight and fast, suitable for real-time applications

Cons of jsQR

  • Limited to QR code reading/detection only
  • May have lower performance compared to native implementations
  • Less comprehensive documentation and examples

Code Comparison

QR-Code-generator (Java):

QrCode qr = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
BufferedImage img = qr.toImage(4, 10);
ImageIO.write(img, "png", new File("qr-code.png"));

jsQR (JavaScript):

const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) {
  console.log("Found QR code", code.data);
}

Key Differences

  • QR-Code-generator supports both encoding and decoding, while jsQR focuses on decoding
  • QR-Code-generator is available in multiple programming languages, jsQR is JavaScript-only
  • jsQR is more suited for web-based applications, while QR-Code-generator offers broader platform support
  • QR-Code-generator provides more customization options for QR code generation
13,583

Cross-browser QRCode generator for javascript

Pros of qrcodejs

  • Lightweight and easy to use, with a simple API
  • Supports various output formats (canvas, table, SVG)
  • No external dependencies, making it ideal for client-side use

Cons of qrcodejs

  • Limited customization options compared to QR-Code-generator
  • Less comprehensive documentation and examples
  • May not support advanced QR code features or error correction levels

Code Comparison

QR-Code-generator (C++):

QrCode qr = QrCode::encodeText("Hello, world!", QrCode::Ecc::MEDIUM);
for (int y = 0; y < qr.getSize(); y++) {
    for (int x = 0; x < qr.getSize(); x++) {
        std::cout << (qr.getModule(x, y) ? "##" : "  ");
    }
    std::cout << std::endl;
}

qrcodejs (JavaScript):

var qrcode = new QRCode(document.getElementById("qrcode"), {
    text: "Hello, world!",
    width: 128,
    height: 128,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.M
});

QR-Code-generator offers more low-level control and supports multiple programming languages, while qrcodejs provides a simpler, JavaScript-focused solution for web applications. QR-Code-generator is better suited for complex projects requiring fine-tuned control, whereas qrcodejs is ideal for quick implementation in web environments.

QR Code Generator implementation in JavaScript, Java and more.

Pros of qrcode-generator

  • Supports multiple programming languages (JavaScript, Java, and others)
  • Provides a simple API for easy integration
  • Includes a demo page for quick testing and visualization

Cons of qrcode-generator

  • Less actively maintained (last update was in 2020)
  • Limited documentation and examples
  • Fewer features compared to QR-Code-generator

Code Comparison

QR-Code-generator (C++):

QrCode qr = QrCode::encodeText("Hello, world!", QrCode::Ecc::MEDIUM);
for (int y = 0; y < qr.getSize(); y++) {
    for (int x = 0; x < qr.getSize(); x++) {
        std::cout << (qr.getModule(x, y) ? "##" : "  ");
    }
    std::cout << std::endl;
}

qrcode-generator (JavaScript):

var qr = qrcode(0, 'M');
qr.addData('Hello, world!');
qr.make();
var moduleCount = qr.getModuleCount();
for (var row = 0; row < moduleCount; row++) {
    for (var col = 0; col < moduleCount; col++) {
        process.stdout.write(qr.isDark(row, col) ? '##' : '  ');
    }
    console.log();
}

Both libraries offer similar functionality for generating QR codes, but QR-Code-generator provides a more comprehensive set of features and is actively maintained. qrcode-generator, while simpler to use, may lack some advanced options and recent updates.

Python QR Code image generator

Pros of python-qrcode

  • Pure Python implementation, making it easier to install and use across different platforms
  • Supports SVG output, allowing for scalable QR codes
  • Includes a command-line interface for quick QR code generation

Cons of python-qrcode

  • Generally slower performance compared to the C++ implementation of QR-Code-generator
  • Limited to QR code generation only, while QR-Code-generator supports both encoding and decoding

Code Comparison

python-qrcode:

import qrcode
qr = qrcode.QRCode(version=1, box_size=10, border=5)
qr.add_data('Hello, World!')
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")

QR-Code-generator:

#include <QrCode.hpp>
using qrcodegen::QrCode;
const QrCode qr = QrCode::encodeText("Hello, World!", QrCode::Ecc::MEDIUM);
std::string svg = qr.toSvgString(4);

Both libraries offer straightforward ways to generate QR codes, with python-qrcode providing a more Pythonic interface and QR-Code-generator offering a C++ implementation for potentially better performance. The choice between them depends on the specific requirements of the project, such as language preference, performance needs, and desired output formats.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

QR Code generator library

Introduction

This 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.

Home page with live JavaScript demo, extensive descriptions, and competitor comparisons: https://www.nayuki.io/page/qr-code-generator-library

Features

Core features:

  • Available in 6 programming languages, all with nearly equal functionality: Java, TypeScript/JavaScript, Python, Rust, C++, C
  • Significantly shorter code but more documentation comments compared to competing libraries
  • 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

Manual parameters:

  • 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

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

More information about QR Code technology and this library's design can be found on the project home page.

Examples

The code below is in Java, but the other language ports are designed with essentially the same API naming and behavior.

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import javax.imageio.ImageIO;
import io.nayuki.qrcodegen.*;

// Simple operation
QrCode qr0 = QrCode.encodeText("Hello, world!", QrCode.Ecc.MEDIUM);
BufferedImage img = toImage(qr0, 4, 10);  // See QrCodeGeneratorDemo
ImageIO.write(img, "png", new File("qr-code.png"));

// Manual operation
List<QrSegment> segs = QrSegment.makeSegments("3141592653589793238462643383");
QrCode qr1 = QrCode.encodeSegments(segs, QrCode.Ecc.HIGH, 5, 5, 2, false);
for (int y = 0; y < qr1.size; y++) {
    for (int x = 0; x < qr1.size; x++) {
        (... paint qr1.getModule(x, y) ...)
    }
}

License

Copyright © 2024 Project Nayuki. (MIT License)
https://www.nayuki.io/page/qr-code-generator-library

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  • The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

  • The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.

NPM DownloadsLast 30 Days