takes an input string and converts it to v40 qr code

This commit is contained in:
Joe Ardent 2023-08-01 13:11:42 -07:00
commit cacd02be91
4 changed files with 3968 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

3881
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

16
Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "godiva"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.3.19", features = ["derive", "env"] }
eframe = { version = "0.22", default-features = false, features = ["default_fonts", "wgpu", "tts", "accesskit"] }
egui_extras = { version = "0.22", default-features = false, features = ["chrono", "image"] }
env_logger = "*"
fast_qr = { version = "0.9", default-features = false, features = ["image"] }
raptorq = "1.7"
# pinning this to resolve conflict between eframe and fast_qr with the image crate
png = "0.17.6"

70
src/main.rs Normal file
View file

@ -0,0 +1,70 @@
use std::ffi::OsString;
use clap::Parser;
use eframe::egui;
use egui_extras::RetainedImage;
use fast_qr::convert::image::ImageBuilder;
#[derive(Parser, Debug)]
#[clap(author, version, trailing_var_arg = true)]
struct Cli {
#[clap(long, short, help = "File to expose")]
pub file: Option<OsString>,
text: Vec<String>,
}
impl Cli {
pub fn text(&self) -> &Vec<String> {
&self.text
}
}
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let cli = Cli::parse();
let content = if let Some(file) = cli.file {
file.to_string_lossy().bytes().collect()
} else {
cli.text().join(" ").bytes().collect()
};
//println!("content: {content}");
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(1200.0, 1200.0)),
..Default::default()
};
eframe::run_native(
"Show an image with eframe/egui",
options,
Box::new(|_cc| Box::new(Flasher { content })),
)
}
struct Flasher {
pub content: Vec<u8>,
}
impl eframe::App for Flasher {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let heading_text = String::from_utf8(self.content.clone()).unwrap();
ui.heading(heading_text);
let qr = fast_qr::QRBuilder::new(self.content.clone())
.version(fast_qr::Version::V40)
.build()
.unwrap();
let bytes = ImageBuilder::default()
.fit_width(1200)
.to_pixmap(&qr)
.encode_png()
.unwrap();
let img = RetainedImage::from_image_bytes("generated qr code", &bytes).unwrap();
img.show(ui);
});
}
}