26 releases (14 breaking)

0.14.0 Mar 14, 2024
0.13.0 Dec 11, 2023
0.12.0 Feb 23, 2020
0.11.1 Dec 22, 2019
0.0.2 Nov 28, 2014

#34 in Images

Download history 12883/week @ 2023-12-23 24798/week @ 2023-12-30 29358/week @ 2024-01-06 31919/week @ 2024-01-13 32422/week @ 2024-01-20 41205/week @ 2024-01-27 35211/week @ 2024-02-03 46189/week @ 2024-02-10 45790/week @ 2024-02-17 53435/week @ 2024-02-24 49933/week @ 2024-03-02 43144/week @ 2024-03-09 49804/week @ 2024-03-16 46131/week @ 2024-03-23 50466/week @ 2024-03-30 24755/week @ 2024-04-06

175,224 downloads per month
Used in 132 crates (89 directly)

MIT/Apache

210KB
4K SLoC

qrcode-rust

Build status crates.io MIT OR Apache 2.0

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

Cargo.toml

[dependencies]
qrcode = "0.13"

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

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

Example

Image generation

use qrcode::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::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::{QrCode, Version, EcLevel};
use qrcode::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::QrCode;
use qrcode::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:

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

Dependencies

~9.5MB
~26K SLoC