1 unstable release

0.1.1 Feb 24, 2025

#467 in Images

Download history 103/week @ 2025-02-21 27/week @ 2025-02-28 1/week @ 2025-03-07

131 downloads per month

MIT license

105KB
2.5K SLoC

QRForge

QRForge is a QR code generator written in Rust. It supports generating QR codes in both raster (PNG) and vector (SVG) formats. The library provides a flexible builder pattern for creating QR codes with various parameters such as version, error correction level, and data segments.

Features

  • Generate QR codes in PNG and SVG formats
  • Support for different QR code versions and error correction levels
  • Structured append for splitting data across multiple QR codes
  • Optional parallel processing with Rayon

Installation

Add the following to your Cargo.toml:

[dependencies]
qrforge = "0.1.0"

To enable optional features:

[dependencies]
qrforge = { version = "0.1.0", features = ["image", "svg", "parallel"] }

Usage

Basic Usage

use qrforge::{QRCode, Mode, ErrorCorrection};

let qr = QRCode::builder()
    .add_segment(Some(Mode::Byte), b"Hello world")
    .error_correction(ErrorCorrection::L)
    .version(1.into())
    .build()
    .unwrap();

Generating a PNG Image

qr.image_builder()
    .set_width(200)
    .set_height(200)
    .set_border(4)
    .build_image_file("hello.png")
    .unwrap();

Generating an SVG Image

qr.svg_builder()
    .set_width(200)
    .set_height(200)
    .set_border(4)
    .build_svg_file("hello.svg")
    .unwrap();

Structured Append

let qr_codes = QRCode::builder()
    .add_segment(Some(Mode::Byte), b"I read the newspaper")
    .add_segment(Some(Mode::Numeric), b"1234567890")
    .error_correction(ErrorCorrection::L)
    .version(Version::V(1))
    .build_with_structual_append()
    .unwrap();

Examples

Examples can be found in the examples directory. To run an example, use the following command:

cargo run --example qrgen_image --features image
cargo run --example qrgen_svg --features svg

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Dependencies

~0–580KB
~12K SLoC