fn qr_data_url(text: &str) -> Result<String> {
    let qr = QrCode::encode_text(text, QrCodeEcc::Low)?;

    let side = qr.size();
    debug_assert!(<u32 as std::convert::TryFrom<i32>>::try_from(side).is_ok());
    let mut img = image::DynamicImage::new_rgb8(QR_SCALE * side as u32, QR_SCALE * side as u32);

    for y in 0..side {
        for x in 0..side {
            if !qr.get_module(x, y) {
                for i in 0..QR_SCALE {
                    for j in 0..QR_SCALE {
                        img.put_pixel(
                            i + QR_SCALE * x as u32,
                            j + QR_SCALE * y as u32,
                            image::Rgba([0xFF, 0xFF, 0xFF, 0xFF]),
                        );
                    }
                }
            }
        }
    }

    let mut data = Vec::new();
    img.write_to(&mut data, image::ImageOutputFormat::Png)?;

    Ok(format!("data:image/png;base64,{}", base64::encode(data)))
}
/// Generate a QR code from a given text and return it as a PNG data url
Generate a QR code from a given text and return it as a PNG data url
Generate a QR code from a given text and return it as a PNG data url
fn qr_data_url(text: &str) -> Result<String> {
    let qr = QrCode::encode_text(text, QrCodeEcc::Low)?;
    let side = qr.size();
    debug_assert!(<u32 as std::convert::TryFrom<i32>>::try_from(side).is_ok());
    let mut img = image::DynamicImage::new_rgb8(QR_SCALE * side as u32, QR_SCALE * side as u32);
    for y in 0..side {
        for x in 0..side {
            if !qr.get_module(x, y) {
                for i in 0..QR_SCALE {
                    for j in 0..QR_SCALE {
                        img.put_pixel(
                            i + QR_SCALE * x as u32,
                            j + QR_SCALE * y as u32,
                            image::Rgba([0xFF, 0xFF, 0xFF, 0xFF]),
                        );
                    }
                }
            }
        }
    }
    let mut data = Vec::new();
    img.write_to(&mut data, image::ImageOutputFormat::Png)?;
    Ok(format!("data:image/png;base64,{}", base64::encode(data)))
}
fn qr_data_url ( text : & str ) -> Result < String > { let qr = QrCode :: encode_text ( text , QrCodeEcc :: Low ) ? ; let side = qr . size ( ) ; debug_assert ! ( u32 as std convert TryFrom i32 try_from ( side ) is_ok ( ) ) ; let mut img = image :: DynamicImage :: new_rgb8 ( QR_SCALE * side as u32 , QR_SCALE * side as u32 ) ; for y in 0 .. side { for x in 0 .. side { if ! qr . get_module ( x , y ) { for i in 0 .. QR_SCALE { for j in 0 .. QR_SCALE { img . put_pixel ( i + QR_SCALE * x as u32 , j + QR_SCALE * y as u32 , image :: Rgba ( [ 0xFF , 0xFF , 0xFF , 0xFF ] ) , ) ; } } } } } let mut data = Vec :: new ( ) ; img . write_to ( & mut data , image :: ImageOutputFormat :: Png ) ? ; Ok ( format ! ( " " base64 encode ( data ) ) ) }
Generate a QR code from a given text and return it as a PNG data url
Generate a QR code from a given text and return it as a PNG data url
text
&str
text
&str