Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magiclen/qrcode-generator
Generate QR Code matrices and images in RAW, PNG and SVG formats.
https://github.com/magiclen/qrcode-generator
qrcode rust
Last synced: 6 days ago
JSON representation
Generate QR Code matrices and images in RAW, PNG and SVG formats.
- Host: GitHub
- URL: https://github.com/magiclen/qrcode-generator
- Owner: magiclen
- License: mit
- Created: 2018-10-25T03:44:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-09T13:59:29.000Z (over 1 year ago)
- Last Synced: 2024-05-03T04:47:50.217Z (8 months ago)
- Topics: qrcode, rust
- Language: Rust
- Homepage:
- Size: 61.5 KB
- Stars: 60
- Watchers: 4
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
QR Code Generator
====================[![CI](https://github.com/magiclen/qrcode-generator/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/qrcode-generator/actions/workflows/ci.yml)
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>`.
```rust
use qrcode_generator::QrCodeEcc;let result: Vec> = qrcode_generator::to_matrix("Hello world!", QrCodeEcc::Low).unwrap();
println!("{:?}", result);
```#### Encode any data to a PNG image stored in a Vec instance.
```rust
use qrcode_generator::QrCodeEcc;let result: Vec = 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.
```rust
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.
```rust
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.
```rust
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.
```rust
use qrcode_generator::{QrCodeEcc, QrSegment};let first = "1234567";
let second = "ABCDEFG";
let segments = [QrSegment::make_numeric(&first), QrSegment::make_alphanumeric(&second)];
let result: Vec> = qrcode_generator::to_matrix_from_segments(&segments, QrCodeEcc::Low).unwrap();
println!("{:?}", result);
```More segments optimization apporaches: [magiclen/qrcode-segments-optimizer](https://github.com/magiclen/qrcode-segments-optimizer)
## Crates.io
https://crates.io/crates/qrcode-generator
## Documentation
https://docs.rs/qrcode-generator
## License
[MIT](LICENSE)