Find a file
2018-11-07 09:05:06 -05:00
examples rustfmt. 2018-07-30 16:59:49 +08:00
src Fix TODO: use sum insted of left fold 2018-11-04 20:40:44 +02:00
.gitignore Enable coveralls. 2016-05-14 23:43:38 +08:00
.travis.yml Test with 1.26.2 instead of 1.26.0, and latest stable instead of 1.27. 2018-07-30 17:37:16 +08:00
Cargo.toml chore: don't depend on image default features 2018-11-07 09:05:06 -05:00
LICENSE-APACHE.txt Relicense as Apache-2 + MIT. 2016-06-08 00:30:47 +08:00
LICENSE-MIT.txt Relicense as Apache-2 + MIT. 2016-06-08 00:30:47 +08:00
README.md Update README as well. 2018-07-30 18:23:08 +08:00
rustfmt.toml Fix clippy warnings. 2018-07-30 17:31:40 +08:00

qrcode-rust

Build status Coverage Status crates.io MIT / Apache 2.0

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

Cargo.toml

[dependencies]
qrcode = "0.8"

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.8", default-features = false }

Example

Image generation

extern crate qrcode;
extern crate image;

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

extern crate qrcode;
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

extern crate qrcode;

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