QR Code Generator
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 QrCodeEcc;
let result: = to_matrix.unwrap;
println!;
Encode any data to a PNG image stored in a Vec instance.
extern crate qrcode_generator;
use QrCodeEcc;
let result: = to_png_to_vec.unwrap;
println!;
Encode any data to a PNG image stored in a file.
extern crate qrcode_generator;
use QrCodeEcc;
to_png_to_file.unwrap;
Encode any data to a SVG image stored in a String instance.
extern crate qrcode_generator;
use QrCodeEcc;
let result: String = to_svg_to_string.unwrap;
println!;
Encode any data to a SVG image stored in a file.
extern crate qrcode_generator;
use QrCodeEcc;
to_svg_to_file.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 generate and to function has its own by_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 QrCodeEcc;
use QrSegment;
let first = "1234567";
let second = "ABCDEFG";
let first_chars: = first.chars.collect;
let second_chars: = second.chars.collect;
let segments = vec!;
let result: = to_matrix_by_segments.unwrap;
println!;
Optimized URL segments
URL is a common type of data used in QR code. The protocol and the host of a URL is case-insensitive, so they can be converted to a upper-case segment and encoded by alphanumeric instead of binary to reduce the size.
You can use the optimize_url_segments
function to create URL segments.
extern crate qrcode_generator;
use QrCodeEcc;
let url = "https://magiclen.org/path/to/12345";
let matrix_1 = to_matrix.unwrap;
let matrix_2 = to_matrix_by_segments.unwrap;
assert!;
Validators Support
Validators
is a crate which can help you validate user input.
To use with Validators support, you have to enable the validator feature for this crate.
[]
= "*"
= ["validator"]
And the optimize_validated_http_url_segments
function is available.
extern crate qrcode_generator;
extern crate validators;
use QrCodeEcc;
use ;
let validator = HttpUrlValidator ;
let url = "https://magiclen.org/path/to/12345";
let validated_http_url = validator.parse_str.unwrap;
let matrix_1 = to_matrix.unwrap;
let matrix_2 = to_matrix_by_segments.unwrap;
assert!;
Crates.io
https://crates.io/crates/qrcode-generator
Documentation
https://docs.rs/qrcode-generator