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

toml [dependencies] qrencode = "*"

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

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

Example

Image generation

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

```rust use qrencode::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 use qrencode::{QrCode, Version, EcLevel}; use qrencode::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!("{}", image); } ```

Generates this SVG:

Output

Unicode string generation

```rust use qrencode::QrCode; use qrencode::render::unicode;

fn main() { let code = QrCode::new("mow mow").unwrap(); let image = code.render::() .darkcolor(unicode::Dense1x2::Light) .lightcolor(unicode::Dense1x2::Dark) .build(); println!("{}", image); } ```

Generates this output:

text █████████████████████████████ █████████████████████████████ ████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████ ████ █ █ █▀ ▀ ▀█ █ █ ████ ████ █▄▄▄█ ██▄ ▀█ █▄▄▄█ ████ ████▄▄▄▄▄▄▄█ ▀▄▀ █▄▄▄▄▄▄▄████ ████▄▀ ▄▀ ▄ █▄█ ▀ ▀█ █▄ ████ ████▄██▄▄▀▄▄▀█▄ ██▀▀█▀▄▄▄████ █████▄▄▄█▄▄█ ▀▀▄█▀▀▀▄█▄▄████ ████ ▄▄▄▄▄ █ ▄▄██▄ ▄ ▀▀████ ████ █ █ █▀▄▄▀▄▄ ▄▄▄▄ ▄████ ████ █▄▄▄█ █▄ █▄▀▄▀██▄█▀████ ████▄▄▄▄▄▄▄█▄████▄█▄██▄██████ █████████████████████████████ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀