Skip to content

Add a way to compute the base64 uri #28

Description

@RCasatta

Some downstream lib use

pub fn string_to_qr(str: &str, pixel_per_module: Option<u8>) -> Result<String, QrError> {
    let qr_code = qr_code::QrCode::new(str)?;
    let mut bmp = qr_code.to_bmp();
    if let Some(pixel_per_module) = pixel_per_module {
        bmp = bmp.add_white_border(2)?;
        if pixel_per_module > 1 {
            bmp = bmp.mul(pixel_per_module)?;
        }
    }
    let mut enc = base64::write::EncoderWriter::new(Vec::new(), &general_purpose::STANDARD);

    bmp.write(&mut enc)?;
    let delegate = enc.finish()?;

    let base64 = String::from_utf8(delegate)?;
    Ok(format!("data:image/bmp;base64,{base64}"))
}

It would be great to have a base64 feature that enable a function like this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions