Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennytm/qrcode-rust
QR code encoder in Rust.
https://github.com/kennytm/qrcode-rust
Last synced: 7 days ago
JSON representation
QR code encoder in Rust.
- Host: GitHub
- URL: https://github.com/kennytm/qrcode-rust
- Owner: kennytm
- License: apache-2.0
- Created: 2014-08-18T21:10:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-14T01:10:19.000Z (11 months ago)
- Last Synced: 2024-04-24T13:28:07.903Z (10 months ago)
- Language: Rust
- Size: 1.09 MB
- Stars: 444
- Watchers: 9
- Forks: 66
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE.txt
Awesome Lists containing this project
README
qrcode-rust
===========[](https://github.com/kennytm/qrcode-rust/actions?query=workflow%3ARust)
[](https://crates.io/crates/qrcode)
[](./LICENSE-APACHE.txt)QR code and Micro QR code encoder in Rust. [Documentation](https://docs.rs/qrcode).
Cargo.toml
----------```toml
[dependencies]
qrcode = "0.14.1"
```The default settings will depend on the `image` crate. If you don't need image generation capability, disable the `default-features`:
```toml
[dependencies]
qrcode = { version = "0.14.1", default-features = false, features = ["std"] }
```Example
-------## Image generation
```rust
use qrcode::QrCode;
use image::Luma;fn main() {
// Encode some data into bits.
let code = QrCode::new(b"01234567").unwrap();// Render the bits into an image.
let image = code.render::>().build();// Save the image.
image.save("/tmp/qrcode.png").unwrap();
}
```Generates this image:

## String generation
```rust
use qrcode::QrCode;fn main() {
let code = QrCode::new(b"Hello").unwrap();
let string = code.render::()
.dark_color('#')
.quiet_zone(false)
.module_dimensions(2, 1)
.build();
println!("{}", string);
}
```Generates this output:
```none
############## ######## ##############
## ## ## ## ##
## ###### ## ## ## ## ## ###### ##
## ###### ## ## ## ## ###### ##
## ###### ## #### ## ## ###### ##
## ## #### ## ## ##
############## ## ## ## ##############
## ##
## ########## ## ## ##########
## ## ######## #### ##
########## #### ## #### ######
## ## #### ########## ####
###### ########## ## ## ##
## ## ## ##
############## ## ## ## ## ####
## ## ## ## ##########
## ###### ## ## ## ## ## ##
## ###### ## #### ########## ##
## ###### ## #### ## #### ##
## ## ## ######## ######
############## #### ## ## ##
```## SVG generation
```rust
use qrcode::{QrCode, Version, EcLevel};
use qrcode::render::svg;fn main() {
let code = QrCode::with_version(b"01234567", Version::Micro(2), EcLevel::L).unwrap();
let image = code.render()
.min_dimensions(200, 200)
.dark_color(svg::Color("#800000"))
.light_color(svg::Color("#ffff80"))
.build();
println!("{}", image);
}
```Generates this SVG:
[](src/test_annex_i_micro_qr_as_svg.svg)
## Unicode string generation
```rust
use qrcode::QrCode;
use qrcode::render::unicode;fn main() {
let code = QrCode::new("mow mow").unwrap();
let image = code.render::()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
println!("{}", image);
}
```Generates this output:
```text
█████████████████████████████
█████████████████████████████
████ ▄▄▄▄▄ █ ▀▀▀▄█ ▄▄▄▄▄ ████
████ █ █ █▀ ▀ ▀█ █ █ ████
████ █▄▄▄█ ██▄ ▀█ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀▄▀ █▄▄▄▄▄▄▄████
████▄▀ ▄▀ ▄ █▄█ ▀ ▀█ █▄ ████
████▄██▄▄▀▄▄▀█▄ ██▀▀█▀▄▄▄████
█████▄▄▄█▄▄█ ▀▀▄█▀▀▀▄█▄▄████
████ ▄▄▄▄▄ █ ▄▄██▄ ▄ ▀▀████
████ █ █ █▀▄▄▀▄▄ ▄▄▄▄ ▄████
████ █▄▄▄█ █▄ █▄▀▄▀██▄█▀████
████▄▄▄▄▄▄▄█▄████▄█▄██▄██████
█████████████████████████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
```## PIC generation
```rust
use qrcode::render::pic;
use qrcode::QrCode;fn main() {
let code = QrCode::new(b"01234567").unwrap();
let image = code
.render::()
.min_dimensions(1, 1)
.build();
println!("{}", image);
}
```Generates [PIC](https://en.wikipedia.org/wiki/PIC_(markup_language))
output that renders as follows:```pic
maxpswid=29;maxpsht=29;movewid=0;moveht=1;boxwid=1;boxht=1
define p { box wid $3 ht $4 fill 1 thickness 0.1 with .nw at $1,-$2 }
box wid maxpswid ht maxpsht with .nw at 0,0
p(4,4,1,1)
p(5,4,1,1)
p(6,4,1,1)
p(7,4,1,1)
p(8,4,1,1)
p(9,4,1,1)
…
```
See [`test_annex_i_micro_qr_as_pic.pic`](src/test_annex_i_micro_qr_as_pic.pic) for a full example.