1 unstable release

0.14.0 Mar 3, 2023

#691 in Images

Download history 213/week @ 2023-12-15 146/week @ 2023-12-22 179/week @ 2023-12-29 918/week @ 2024-01-05 959/week @ 2024-01-12 498/week @ 2024-01-19 394/week @ 2024-01-26 483/week @ 2024-02-02 412/week @ 2024-02-09 341/week @ 2024-02-16 595/week @ 2024-02-23 325/week @ 2024-03-01 274/week @ 2024-03-08 303/week @ 2024-03-15 384/week @ 2024-03-22 534/week @ 2024-03-29

1,540 downloads per month
Used in 3 crates

MIT/Apache

210KB
4K SLoC

qrencode

A fork of qm3ster/qrcode-rust, which is a fork of kennytm/qrcode-rust.

Since the original crate has stopped being maintained, and two of my projects depend on it, I'll be maintaining this fork until the original author returns. Any help from the community is appreciated.

Cargo.toml

[dependencies]
qrencode = "*"

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

[dependencies]
qrencode = { version = "*", default-features = false }

Example

Image generation

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