Crates.io | qrcode-generator |
lib.rs | qrcode-generator |
version | 5.0.0 |
source | src |
created_at | 2018-10-25 03:51:25.725031 |
updated_at | 2024-10-23 05:59:42.789162 |
description | Generate QR Code matrices and images in RAW, PNG and SVG formats. |
homepage | https://magiclen.org/qrcode-generator |
repository | https://github.com/magiclen/qrcode-generator |
max_upload_size | |
id | 92527 |
size | 26,348 |
This crate provides functions to generate QR Code matrices and images in RAW, PNG and SVG formats.
Vec<Vec<bool>>
.use qrcode_generator::QrCodeEcc;
let result: Vec<Vec<bool>> = qrcode_generator::to_matrix("Hello world!", QrCodeEcc::Low).unwrap();
println!("{:?}", result);
use qrcode_generator::QrCodeEcc;
let result: Vec<u8> = qrcode_generator::to_png_to_vec("Hello world!", QrCodeEcc::Low, 1024).unwrap();
println!("{:?}", result);
use qrcode_generator::QrCodeEcc;
qrcode_generator::to_png_to_file("Hello world!", QrCodeEcc::Low, 1024, "tests/data/file_output.png").unwrap();
use qrcode_generator::QrCodeEcc;
let result: String = qrcode_generator::to_svg_to_string("Hello world!", QrCodeEcc::Low, 1024, None::<&str>).unwrap();
println!("{:?}", result);
use qrcode_generator::QrCodeEcc;
qrcode_generator::to_svg_to_file("Hello world!", QrCodeEcc::Low, 1024, None::<&str>, "tests/data/file_output.svg").unwrap();
The to_image
and to_image_buffer
functions can be used, if you want to modify your image.
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.
use qrcode_generator::{QrCodeEcc, QrSegment};
let first = "1234567";
let second = "ABCDEFG";
let segments = [QrSegment::make_numeric(&first), QrSegment::make_alphanumeric(&second)];
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
https://crates.io/crates/qrcode-generator
https://docs.rs/qrcode-generator