Crate qrcode_generator[−][src]
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 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
Re-exports
pub extern crate qrcodegen; |
Structs
QrSegment | A segment of character/binary/control data in a QR Code symbol. |
Enums
QRCodeError | Errors when encoding QR code. |
QrCodeEcc | The error correction level in a QR Code symbol. |
Functions
to_image | Encode data to raw image in memory. |
to_image_buffer | Encode data to a image buffer. |
to_image_buffer_from_segments | Encode segments to a image buffer. |
to_image_buffer_from_str | Encode text to a image buffer. |
to_image_from_segments | Encode segments to raw image in memory. |
to_image_from_str | Encode text to raw image in memory. |
to_matrix | Encode data to a QR code matrix. |
to_matrix_from_segments | Encode segments to a QR code matrix. |
to_matrix_from_str | Encode text to a QR code matrix. |
to_png_to_file | Encode data to a PNG image via a file path. |
to_png_to_file_from_segments | Encode text to a PNG image via a file path. |
to_png_to_file_from_str | Encode text to a PNG image via a file path. |
to_png_to_vec | Encode data to a PNG image in memory. |
to_png_to_vec_from_segments | Encode segments to a PNG image in memory. |
to_png_to_vec_from_str | Encode text to a PNG image in memory. |
to_png_to_writer | Encode data to a PNG image via a writer. |
to_png_to_writer_from_segments | Encode segments to a PNG image via a writer. |
to_png_to_writer_from_str | Encode text to a PNG image via a writer. |
to_svg_to_file | Encode data to a SVG image via a file path. |
to_svg_to_file_from_segments | Encode segments to a SVG image via a file path. |
to_svg_to_file_from_str | Encode text to a SVG image via a file path. |
to_svg_to_string | Encode data to a SVG image in memory. |
to_svg_to_string_from_segments | Encode segments to a SVG image in memory. |
to_svg_to_string_from_str | Encode text to a SVG image in memory. |
to_svg_to_writer | Encode data to a SVG image via a writer. |
to_svg_to_writer_from_segments | Encode segments to a SVG image via a writer. |
to_svg_to_writer_from_str | Encode text to a SVG image via a writer. |