minify the output size

This commit is contained in:
blek 2023-10-10 01:12:11 +10:00
parent 8aac2981d7
commit 7cf00857bb
Signed by: blek
GPG Key ID: 14546221E3595D0C
3 changed files with 17 additions and 3 deletions

7
Cargo.lock generated
View File

@ -533,6 +533,7 @@ dependencies = [
"image",
"qrcode",
"tokio",
"urlencoding",
"warp",
]
@ -1191,6 +1192,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]]
name = "utf-8"
version = "0.7.6"

View File

@ -9,6 +9,7 @@ edition = "2021"
image = "0.23.0"
qrcode = "0.12.0"
tokio = { version = "1.33.0", features = ["full"] }
urlencoding = "2.1.3"
warp = "0.3.6"
[profile.release]

View File

@ -1,5 +1,6 @@
use qrcode::QrCode;
use image::{Luma, png::PngEncoder};
use urlencoding::decode;
use warp::{Filter, reply::Response};
@ -14,9 +15,14 @@ async fn main() {
.and(
warp::get()
)
.map(|x| {
let code = QrCode::new(x).unwrap();
let img = code.render::<Luma<u8>>().build();
.map(|x: String| {
let text = decode(x.as_str()).unwrap().to_string();
let code = QrCode::with_error_correction_level(text, qrcode::EcLevel::M).unwrap();
let img = code
.render::<Luma<u8>>()
.quiet_zone(false)
.module_dimensions(1, 1)
.build();
let mut out = Vec::<u8>::new();
let enc = PngEncoder::new(&mut out);