Crates.io | qrc |
lib.rs | qrc |
version | 0.0.5 |
source | src |
created_at | 2023-02-05 01:14:15.231413 |
updated_at | 2023-12-29 01:39:04.250602 |
description | A Rust library for generating and manipulating QR code images in various formats |
homepage | https://qrclib.one |
repository | https://github.com/sebastienrousseau/qrc/ |
max_upload_size | |
id | 776755 |
size | 92,969 |
A Rust library for generating and manipulating QR code images in various formats 🦀
Website • Documentation • Report Bug • Request Feature • Contributing Guidelines
The QR Code Library (QRC) is a comprehensive Rust library designed to create and manipulate QR codes. It offers a wide range of functionalities including generating QR codes in various formats, customizing color schemes, adding image watermarks, and more.
Here are some basic examples of how to use QRC in your Rust projects:
// Create a new QRCode using the QRCode::from_string() function and convert it to a PNG representation
let qrcode = QRCode::from_string(URL.to_string());
// Convert the QRCode into a PNG representation
let png = qrcode.to_png(512);
// Convert the PNG representation of the QRCode into a vector of bytes
let png_data = png.into_raw();
let png_image = ImageBuffer::<Rgba<u8>, Vec<u8>>::from_raw(21, 21, png_data).unwrap();
// Print the PNG representation of the QRCode
println!("fn to_png(): {:?}", png_image.save("qrcode.png"));
match png_image.save("qrcode.png") {
// Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png"
Ok(_) => println!("png file created: qrcode.png"),
// Print the path to the PNG representation of the QRCode that was saved to a file called "qrcode.png"
Err(e) => println!("png file created: qrcode.png: {e}"),
}
The QR Code Library (QRC) offers a set of macros for easy manipulation and generation of QR codes in Rust. Below is the documentation for each macro available in the library.
add_image_watermark
add_image_watermark!(img, watermark);
img
: An expression representing the main image.watermark
: An expression representing the watermark image.qr_code
qr_code!(data);
data
: An expression representing the data to encode in the QR code.qr_code_to
qr_code_to!(data, format, width);
data
: The data to encode.format
: The desired output format ("png", "jpg", or "gif").width
: The width of the QR code.resize
resize!(qrcode, size);
qrcode
: An instance of QRCode
.size
: The desired size for the QR code.set_encoding_format
set_encoding_format!(qr_code, format);
qr_code
: An instance of QRCode
.format
: The encoding format for the QR code data.overlay_image
overlay_image!(qr_code, image_path);
qr_code
: QRCode instance to which the image will be overlaid.image_path
: Path to the image file to overlay.batch_generate_qr
batch_generate_qr!(data_list);
data_list
: A vector of data strings for QR code generation.compress_data_macro
compress_data_macro!(data);
data
: The data to be compressed and encoded.combine_qr_codes
combine_qr_codes!(codes);
codes
: An array of QRCode instances to combine.create_dynamic_qr
create_dynamic_qr!(initial_data);
initial_data
: The initial data for the QR code.create_multilanguage_qr
create_multilanguage_qr! {
"en" => "Hello",
"es" => "Hola",
"fr" => "Bonjour",
};
It takes just a few minutes to get up and running with qrc
.
qrc
requires Rust 1.71.1 or later.
You can find detailed documentation for QRC on lib.rs, crates.io and docs.rs.
To use qrc
in your project, add the following to your
Cargo.toml
file:
[dependencies]
qrc = "0.0.5"
Add the following to your main.rs
file:
extern crate qrc;
use qrc::*;
then you can use the functions in your application code.
QRC
comes with a set of examples that you can use to get started. The
examples are located in the examples
directory of the project. To run
the examples, clone the repository and run the following command in your
terminal from the project root directory.
cargo run --example example
For transparency into our release cycle and in striving to maintain
backward compatibility, QRC
follows semantic versioning.
The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
A big thank you to all the awesome contributors of QRC for their help and support. A special thank you goes to the Rust Reddit community for providing a lot of useful suggestions on how to improve this project.