1 unstable release
0.14.0 | Mar 3, 2023 |
---|
#849 in Images
2,444 downloads per month
Used in 2 crates
210KB
4K
SLoC
qrencode
A fork of qm3ster/qrcode-rust, which is a fork of kennytm/qrcode-rust.
Since the original crate has stopped being maintained, and two of my projects depend on it, I'll be maintaining this fork until the original author returns. Any help from the community is appreciated.
Cargo.toml
[dependencies]
qrencode = "*"
The default settings will depend on the image
crate. If you don't need image generation capability, disable the default-features
:
[dependencies]
qrencode = { version = "*", default-features = false }
Example
Image generation
use qrencode::QrCode;
use image::Luma;
fn main() {
// Encode some data into bits.
let code = QrCode::new(b"01234567").unwrap();
// Render the bits into an image.
let image = code.render::<Luma<u8>>().build();
// Save the image.
image.save("/tmp/qrcode.png").unwrap();
}
Generates this image:
String generation
use qrencode::QrCode;
fn main() {
let code = QrCode::new(b"Hello").unwrap();
let string = code.render::<char>()
.quiet_zone(false)
.module_dimensions(2, 1)
.build();
println!("{}", string);
}
Generates this output:
############## ######## ##############
## ## ## ## ##
## ###### ## ## ## ## ## ###### ##
## ###### ## ## ## ## ###### ##
## ###### ## #### ## ## ###### ##
## ## #### ## ## ##
############## ## ## ## ##############
## ##
## ########## ## ## ##########
## ## ######## #### ##
########## #### ## #### ######
## ## #### ########## ####
###### ########## ## ## ##
## ## ## ##
############## ## ## ## ## ####
## ## ## ## ##########
## ###### ## ## ## ## ## ##
## ###### ## #### ########## ##
## ###### ## #### ## #### ##
## ## ## ######## ######
############## #### ## ## ##
SVG generation
use qrencode::{QrCode, Version, EcLevel};
use qrencode::render::svg;
fn main() {
let code = QrCode::with_version(b"01234567", Version::Micro(2), EcLevel::L).unwrap();
let image = code.render()
.min_dimensions(200, 200)
.dark_color(svg::Color("#800000"))
.light_color(svg::Color("#ffff80"))
.build();
println!("{}", image);
}
Generates this SVG:
Unicode string generation
use qrencode::QrCode;
use qrencode::render::unicode;
fn main() {
let code = QrCode::new("mow mow").unwrap();
let image = code.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
println!("{}", image);
}
Generates this output:
█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████
████ █ █ █▀ ▀ ▀█ █ █ ████
████ █▄▄▄█ ██▄ ▀█ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀▄▀ █▄▄▄▄▄▄▄████
████▄▀ ▄▀ ▄ █▄█ ▀ ▀█ █▄ ████
████▄██▄▄▀▄▄▀█▄ ██▀▀█▀▄▄▄████
█████▄▄▄█▄▄█ ▀▀▄█▀▀▀▄█▄▄████
████ ▄▄▄▄▄ █ ▄▄██▄ ▄ ▀▀████
████ █ █ █▀▄▄▀▄▄ ▄▄▄▄ ▄████
████ █▄▄▄█ █▄ █▄▀▄▀██▄█▀████
████▄▄▄▄▄▄▄█▄████▄█▄██▄██████
█████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Dependencies
~1.5MB
~26K SLoC