erwanvivien / fast_qr

Ultra fast QRCode generation
https://fast-qr.com/
MIT License
196 stars 29 forks source link

SvgBuilder does not utilize Base64 strings for Image properly #60

Closed sollambert closed 2 weeks ago

sollambert commented 1 month ago

When creating an SVG using SvgBuilder, it does not infer to use a passed Base64 string as src for image and instead inserts the string into the href attribute of the constructed image tag.

Documentation implies this functionality is not intended, and a Base64 string should be able to be used as the image src. https://docs.rs/fast_qr/latest/fast_qr/convert/trait.Builder.html#tymethod.image

erwanvivien commented 1 month ago

Thanks for the report! Do you have repro code?

sollambert commented 1 month ago

This should work for repro, untested. When the SVG element is created, the Base64 string is placed into the href attribute of the tag, whereas the data should be in the src attribute.

Should just be able to check if there is a successful Base64 decode of the passed string to the image function, unless we're expecting Base64 encoded URIs to be passed as well.

fn repro() {
    let qr = QRBuilder::new("This is the QR data").build().unwrap();
    let mut svg_builder = convert::svg::SvgBuilder::default();
    svg_builder.image("BASE_64_STRING_HERE".to_string());
    svg_builder.to_str(&qr);
}
erwanvivien commented 1 month ago

Hey thanks for the repro.

Unfortunately I think you are confusing <image> which are for SVGs and <img> which is HTML <image> uses href instead of src see the example in the page I linked a bit bellow

sollambert commented 1 month ago

Ah, well for whatever reason I was unable to display the image that was supplied as a base64 string wither with a MIME type prefix or without, wonder why that was the case.

erwanvivien commented 2 weeks ago

I'll let you re-open if you are having the same problem