1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use qrcode::{EcLevel, QrCode, Version};
use qrcode::render::{svg, unicode};
use image::Luma;
pub fn qrcode_create_string(text: &str) -> String {
let code = QrCode::new(text).unwrap();
let string = code.render::<char>()
.quiet_zone(false)
.module_dimensions(2, 1)
.build();
string
}
pub fn qrcode_create_unicode(text: &str) -> String {
let code = QrCode::new(text).unwrap();
let string = code.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Light)
.light_color(unicode::Dense1x2::Dark)
.build();
string
}
pub fn qrcode_create_svg(text: &str) -> String {
let code = QrCode::with_version(text, 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();
image
}
pub fn qrcode_create_png(text: &str, filename: &str) -> bool {
let code = QrCode::new(text).unwrap();
let image = code.render::<Luma<u8>>()
.min_dimensions(200, 200)
.build();
match image.save(filename) {
Ok(()) => true,
Err(_) => false
}
}