#qrcode #png

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

#25 in #qrcode

Download history 10/week @ 2024-06-10 4/week @ 2024-06-17 6/week @ 2024-06-24 21/week @ 2024-07-01 1/week @ 2024-07-08 8/week @ 2024-07-15 12/week @ 2024-07-29 10/week @ 2024-08-05 7/week @ 2024-08-12 1/week @ 2024-08-19 3/week @ 2024-09-02 8/week @ 2024-09-09 6/week @ 2024-09-16 44/week @ 2024-09-23

61 downloads per month
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