Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can I use this in a web application? #53

Open
Raj2032 opened this issue Dec 25, 2021 · 4 comments
Open

can I use this in a web application? #53

Raj2032 opened this issue Dec 25, 2021 · 4 comments

Comments

@Raj2032
Copy link

Raj2032 commented Dec 25, 2021

Hi, I wanted to ask you, I wanted to make a web application that uses qrcode-rust library. Is it possible for me to compile it to wasm and this will work ok?

@enaut
Copy link

enaut commented May 10, 2022

@Raj2032
Copy link
Author

Raj2032 commented May 10, 2022

@enaut I see thanks mate

@enaut
Copy link

enaut commented May 10, 2022

No problem it took me quite some time to figure everything out. So I'm glad if that code can help someone to reduce that time for them :)

@fc7
Copy link

fc7 commented Jun 19, 2022

Alternative to @enaut's generate_qr_png, using image::codecs:png::PngEncoder directly:

fn qrcode_png(content: &String) -> Vec<u8> {
    let qrcode = QrCode::new(content).unwrap();
    let image: image::ImageBuffer<Luma<u8>, Vec<u8>> = qrcode.render::<Luma<u8>>().build();
    let mut buf: Vec<u8> = Vec::new();
    let wd: u32 = image.width();
    let ht: u32 = image.height();
    let encoder: PngEncoder<&mut Vec<u8>> = PngEncoder::new(&mut buf);
    encoder.encode(&image.into_raw(), wd, ht, ColorType::L8).expect("Cannot encode image");
    buf
}

You could return this as a response body, for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants