#qrcode #image #barcode #encoder #generate #image-format

bin+lib qrcode-rs

QR code encoder in Rust,Generate QR Code matrices and images in RAW, PNG and SVG formats

6 releases

new 0.1.5 May 20, 2024
0.1.4 May 20, 2024
0.1.3 Mar 3, 2024
0.1.2 May 23, 2023
0.1.0 Dec 11, 2022

#182 in Images

Download history 154/week @ 2024-01-31 124/week @ 2024-02-07 318/week @ 2024-02-14 240/week @ 2024-02-21 339/week @ 2024-02-28 26/week @ 2024-03-06 15/week @ 2024-03-13 2/week @ 2024-03-20 8/week @ 2024-03-27 14/week @ 2024-04-03 4/week @ 2024-04-10 15/week @ 2024-04-17 53/week @ 2024-04-24 79/week @ 2024-05-01 9/week @ 2024-05-08 269/week @ 2024-05-15

413 downloads per month
Used in 4 crates (via vercre-core)

MIT/Apache

215KB
4K SLoC

Qrcode-rs

Build crates.io docs.rs License Crates.io

QR code and Micro QR code encoder in Rust. Documentation.

Cargo.toml

[dependencies]
qrcode-rs = "0.1"

The default settings will depend on the image crate. If you don't need image generation capability, disable the default-features:

[dependencies]
qrcode-rs = { version = "0.1", default-features = false }

Example

Image generation

use qrcode_rs::QrCode;
use image::Luma;

fn main() {
    // Encode some data into bits.
    let code = QrCode::new(b"01234567").unwrap();

    // Render the bits into an image.
    let image = code.render::<Luma<u8>>().build();

    // Save the image.
    image.save("/tmp/qrcode.png").unwrap();
}

Generates this image:

Output

String generation

use qrcode_rs::QrCode;

fn main() {
    let code = QrCode::new(b"Hello").unwrap();
    let string = code.render::<char>()
        .quiet_zone(false)
        .module_dimensions(2, 1)
        .build();
    println!("{}", string);
}

Generates this output:

##############    ########  ##############
##          ##          ##  ##          ##
##  ######  ##  ##  ##  ##  ##  ######  ##
##  ######  ##  ##  ##      ##  ######  ##
##  ######  ##  ####    ##  ##  ######  ##
##          ##  ####  ##    ##          ##
##############  ##  ##  ##  ##############
                ##  ##
##  ##########    ##  ##    ##########
      ##        ##    ########    ####  ##
    ##########    ####  ##  ####  ######
    ##    ##  ####  ##########    ####
  ######    ##########  ##    ##        ##
                ##      ##    ##  ##
##############    ##  ##  ##    ##  ####
##          ##  ##  ##        ##########
##  ######  ##  ##    ##  ##    ##    ##
##  ######  ##  ####  ##########  ##
##  ######  ##  ####    ##  ####    ##
##          ##    ##  ########  ######
##############  ####    ##      ##    ##

SVG generation

use qrcode_rs::{QrCode, Version, EcLevel};
use qrcode_rs::render::svg;

fn main() {
    let code = QrCode::with_version(b"01234567", Version::Micro(2), EcLevel::L).unwrap();
    let image = code.render()
        .min_dimensions(200, 200)
        .dark_color(svg::Color("#800000"))
        .light_color(svg::Color("#ffff80"))
        .build();
    println!("{}", image);
}

Generates this SVG:

Output

Unicode string generation

use qrcode_rs::QrCode;
use qrcode_rs::render::unicode;

fn main() {
    let code = QrCode::new("mow mow").unwrap();
    let image = code.render::<unicode::Dense1x2>()
        .dark_color(unicode::Dense1x2::Light)
        .light_color(unicode::Dense1x2::Dark)
        .build();
    println!("{}", image);
}

Generates this output:

█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████
████ █   █ █▀ ▀ ▀█ █   █ ████
████ █▄▄▄█ ██▄  ▀█ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀▄▀ █▄▄▄▄▄▄▄████
████▄▀ ▄▀ ▄ █▄█  ▀ ▀█ █▄ ████
████▄██▄▄▀▄▄▀█▄ ██▀▀█▀▄▄▄████
█████▄▄▄█▄▄█  ▀▀▄█▀▀▀▄█▄▄████
████ ▄▄▄▄▄ █   ▄▄██▄ ▄ ▀▀████
████ █   █ █▀▄▄▀▄▄ ▄▄▄▄ ▄████
████ █▄▄▄█ █▄  █▄▀▄▀██▄█▀████
████▄▄▄▄▄▄▄█▄████▄█▄██▄██████
█████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Thanks to Kennytm, this package is based on qrcode-rust.

Dependencies

~9.5MB
~26K SLoC