#qrcode #generate #png #svg #vec

no-std qrcode-generator

Generate QR Code matrices and images in RAW, PNG and SVG formats

11 stable releases

new 4.1.0 Apr 22, 2021
4.0.4 Nov 13, 2020
4.0.3 Jul 29, 2020
1.0.6 Feb 23, 2020
1.0.3 Nov 4, 2018

#19 in Images

Download history 37/week @ 2020-12-31 40/week @ 2021-01-07 68/week @ 2021-01-14 37/week @ 2021-01-21 36/week @ 2021-01-28 26/week @ 2021-02-04 69/week @ 2021-02-11 69/week @ 2021-02-18 80/week @ 2021-02-25 33/week @ 2021-03-04 74/week @ 2021-03-11 59/week @ 2021-03-18 104/week @ 2021-03-25 67/week @ 2021-04-01 67/week @ 2021-04-08 75/week @ 2021-04-15

267 downloads per month
Used in 5 crates

MIT license

28KB
567 lines

QR Code Generator

CI

This crate provides functions to generate QR Code matrices and images in RAW, PNG and SVG formats.

Examples

Encode any data to a QR Code matrix which is Vec<Vec<bool>>.

extern crate qrcode_generator;

use qrcode_generator::QrCodeEcc;

let result: Vec<Vec<bool>> = qrcode_generator::to_matrix("Hello world!", QrCodeEcc::Low).unwrap();

println!("{:?}", result);

Encode any data to a PNG image stored in a Vec instance.

extern crate qrcode_generator;

use qrcode_generator::QrCodeEcc;

let result: Vec<u8> = qrcode_generator::to_png_to_vec("Hello world!", QrCodeEcc::Low, 1024).unwrap();

println!("{:?}", result);

Encode any data to a PNG image stored in a file.

extern crate qrcode_generator;

use qrcode_generator::QrCodeEcc;

qrcode_generator::to_png_to_file("Hello world!", QrCodeEcc::Low, 1024, "tests/data/file_output.png").unwrap();

Encode any data to a SVG image stored in a String instance.

extern crate qrcode_generator;

use qrcode_generator::QrCodeEcc;

let result: String = qrcode_generator::to_svg_to_string("Hello world!", QrCodeEcc::Low, 1024, None::<&str>).unwrap();

println!("{:?}", result);

Encode any data to a SVG image stored in a file.

extern crate qrcode_generator;

use qrcode_generator::QrCodeEcc;

qrcode_generator::to_svg_to_file("Hello world!", QrCodeEcc::Low, 1024, None::<&str>, "tests/data/file_output.png").unwrap();

Low-level Usage

Raw Image Data

The to_image and to_image_buffer functions can be used, if you want to modify your image.

Segments

Every to_* function has a corresponding _from_segments function. You can concatenate segments by using different encoding methods, such as numeric, alphanumeric or binary to reduce the size (level) of your QR code matrix/image.

extern crate qrcode_generator;

use qrcode_generator::{QrCodeEcc, QrSegment};

let first = "1234567";

let second = "ABCDEFG";

let first_chars: Vec<char> = first.chars().collect();
let second_chars: Vec<char> = second.chars().collect();

let segments = [QrSegment::make_numeric(&first_chars), QrSegment::make_alphanumeric(&second_chars)];

let result: Vec<Vec<bool>> = qrcode_generator::to_matrix_from_segments(&segments, QrCodeEcc::Low).unwrap();

println!("{:?}", result);

More segments optimization apporaches: magiclen/qrcode-segments-optimizer

No Std

Disable the default features to compile this crate without std.

[dependencies.qrcode-generator]
version = "*"
default-features = false

Crates.io

https://crates.io/crates/qrcode-generator

Documentation

https://docs.rs/qrcode-generator

License

MIT

Dependencies

~4MB
~51K SLoC