#qrcode #png #encoder #image

qrcode-png

Generate QR code in png format

2 releases

0.4.1 Sep 7, 2022
0.4.0 Mar 22, 2022
0.3.0 Feb 23, 2022
0.2.1 Feb 23, 2022
0.0.2 May 31, 2020

#902 in Images


Used in 2 crates

MIT license

9KB
138 lines

qrcode-png

Crates.io LICENSE

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();
}

qrcode


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