#qrcode #png #svg #generate #vec

qrcode-generator

Generate QR Code matrices and images in RAW, PNG and SVG formats

21 stable releases

5.0.0 Oct 23, 2024
4.1.9 Sep 9, 2023
4.1.8 Apr 11, 2023
4.1.7 Dec 15, 2022
1.0.3 Nov 4, 2018

#36 in Images

Download history 12162/week @ 2024-07-30 14240/week @ 2024-08-06 10705/week @ 2024-08-13 16565/week @ 2024-08-20 14207/week @ 2024-08-27 15040/week @ 2024-09-03 14014/week @ 2024-09-10 14135/week @ 2024-09-17 17258/week @ 2024-09-24 17396/week @ 2024-10-01 17040/week @ 2024-10-08 16130/week @ 2024-10-15 18448/week @ 2024-10-22 18894/week @ 2024-10-29 16953/week @ 2024-11-05 14022/week @ 2024-11-12

70,916 downloads per month
Used in 19 crates (18 directly)

MIT license

26KB
528 lines

QR Code Generator

CI

This crate provides functions to generate QR Code matrices and images in RAW, PNG and SVG formats.

Examples

Encode any data to a QR Code matrix which is Vec<Vec<bool>>.

use qrcode_generator::QrCodeEcc;

let result: Vec<Vec<bool>> = qrcode_generator::to_matrix("Hello world!", QrCodeEcc::Low).unwrap();

println!("{:?}", result);

Encode any data to a PNG image stored in a Vec instance.

use qrcode_generator::QrCodeEcc;

let result: Vec<u8> = qrcode_generator::to_png_to_vec("Hello world!", QrCodeEcc::Low, 1024).unwrap();

println!("{:?}", result);

Encode any data to a PNG image stored in a file.

use qrcode_generator::QrCodeEcc;

qrcode_generator::to_png_to_file("Hello world!", QrCodeEcc::Low, 1024, "tests/data/file_output.png").unwrap();

Encode any data to a SVG image stored in a String instance.

use qrcode_generator::QrCodeEcc;

let result: String = qrcode_generator::to_svg_to_string("Hello world!", QrCodeEcc::Low, 1024, None::<&str>).unwrap();

println!("{:?}", result);

Encode any data to a SVG image stored in a file.

use qrcode_generator::QrCodeEcc;

qrcode_generator::to_svg_to_file("Hello world!", QrCodeEcc::Low, 1024, None::<&str>, "tests/data/file_output.svg").unwrap();

Low-level Usage

Raw Image Data

The to_image and to_image_buffer functions can be used, if you want to modify your image.

Segments

Every to_* function has a corresponding _from_segments function. You can concatenate segments by using different encoding methods, such as numeric, alphanumeric or binary to reduce the size (level) of your QR code matrix/image.

use qrcode_generator::{QrCodeEcc, QrSegment};

let first = "1234567";

let second = "ABCDEFG";

let segments = [QrSegment::make_numeric(&first), QrSegment::make_alphanumeric(&second)];

let result: Vec<Vec<bool>> = qrcode_generator::to_matrix_from_segments(&segments, QrCodeEcc::Low).unwrap();

println!("{:?}", result);

More segments optimization apporaches: magiclen/qrcode-segments-optimizer

Crates.io

https://crates.io/crates/qrcode-generator

Documentation

https://docs.rs/qrcode-generator

License

MIT

Dependencies

~2.5MB
~53K SLoC