2 releases
0.4.1 | Sep 7, 2022 |
---|---|
0.4.0 | Mar 22, 2022 |
0.3.0 |
|
0.2.1 |
|
0.0.2 |
|
#25 in #qrcode
61 downloads per month
Used in 2 crates
9KB
138 lines
qrcode-png
Generate QR code in png format
Install
Add this in your Cargo.toml
:
[dependencies]
qrcode-png = "*"
Example
use qrcode_png::*;
fn main() {
let mut qrcode = QrCode::new(b"Hello Rust !", QrCodeEcc::Medium).unwrap();
qrcode.margin(10);
qrcode.zoom(10);
let buf = qrcode.generate(Color::Grayscale(0, 255)).unwrap();
std::fs::write("./qrcode.png", buf).unwrap();
}
lib.rs
:
Create a QR code
use qrcode_png::{QrCode, QrCodeEcc, Color};
let mut qrcode = QrCode::new(b"Hello Rust !", QrCodeEcc::Medium).unwrap();
qrcode.zoom(10).margin(10);
// -------- Bitmap
let buf = qrcode.generate(Color::Bitmap(false, true)).unwrap();
std::fs::write("./qrcode.bitmap.png", buf).unwrap();
// -------- Grayscale
let buf = qrcode.generate(Color::Grayscale(0, 255)).unwrap();
std::fs::write("./qrcode.grayscale.png", buf).unwrap();
// -------- RGB
let buf = qrcode
.generate(Color::Rgb([3, 169, 244], [113, 140, 0]))
.unwrap();
std::fs::write("./qrcode.rgb.png", buf).unwrap();
// -------- RGBA
let buf = qrcode
.generate(Color::Rgba([137, 89, 168, 255], [255, 255, 255, 0]))
.unwrap();
std::fs::write("./qrcode.rgba.png", buf).unwrap();
Dependencies
~1MB
~21K SLoC