qrcode-rust

Build status Coverage Status crates.io MIT / Apache 2.0

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

Cargo.toml

toml [dependencies] qrcode = "0.5"

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

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

Example

Image generation

```rust 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

```rust extern crate qrcode; use qrcode::QrCode;

fn main() { let code = QrCode::new(b"Hello").unwrap(); let string = code.render::() .quietzone(false) .moduledimensions(2, 1) .build(); println!("{}", string); } ```

Generates this output:

```none

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

## ## ##

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

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

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

## #### ## ##

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

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

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

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

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

## ## ##

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

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

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

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

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

```

SVG generation

```rust extern crate qrcode;

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

fn main() { let code = QrCode::withversion(b"01234567", Version::Micro(2), EcLevel::L).unwrap(); let image = code.render() .mindimensions(200, 200) .darkcolor(svg::Color("#800000")) .lightcolor(svg::Color("#ffff80")) .build(); println!("{}", string); } ```

Generates this SVG:

Output