fn convert_img_to_base64(src: String) -> String {
    // already data uri scheme
    if src.starts_with("data:") {
        return src;
    }
    let path = Path::new(&src);
    let mime = mime_guess::from_path(&path);
    if let Some(m) = mime.first_raw() {
        let f = File::open(&path);
        if f.is_err() {
            warn!(r#"img source error: src="{}", {}"#, &src, &f.err().unwrap());
            return src;
        }

        let mut f = f.ok().unwrap();
        let mut buf = Vec::new();
        let _ = f.read_to_end(&mut buf).unwrap();

        let buf = base64::encode(buf);

        let res = format!("data:{mime_type};base64,{data}", mime_type = m, data = buf);
        return res;
    }
    src
}
/// convert image source path to data uri scheme  
/// if failed to read file, just return original src
convert image source path to data uri scheme
if failed to read file, just return original src
convert image source path to data uri scheme if failed to read file just return original src
fn convert_img_to_base64(src: String) -> String {
    // already data uri scheme
    if src.starts_with("data:") {
        return src;
    }
    let path = Path::new(&src);
    let mime = mime_guess::from_path(&path);
    if let Some(m) = mime.first_raw() {
        let f = File::open(&path);
        if f.is_err() {
            warn!(r#"img source error: src="{}", {}"#, &src, &f.err().unwrap());
            return src;
        }
        let mut f = f.ok().unwrap();
        let mut buf = Vec::new();
        let _ = f.read_to_end(&mut buf).unwrap();
        let buf = base64::encode(buf);
        let res = format!("data:{mime_type};base64,{data}", mime_type = m, data = buf);
        return res;
    }
    src
}
fn convert_img_to_base64 ( src : String ) -> String { // already data uri scheme if src . starts_with ( " " ) { return src ; } let path = Path :: new ( & src ) ; let mime = mime_guess :: from_path ( & path ) ; if let Some ( m ) = mime . first_raw ( ) { let f = File :: open ( & path ) ; if f . is_err ( ) { warn ! ( r#"img source error: src="{}", {}"# src f err ( ) unwrap ( ) ) ; return src ; } let mut f = f . ok ( ) . unwrap ( ) ; let mut buf = Vec :: new ( ) ; let _ = f . read_to_end ( & mut buf ) . unwrap ( ) ; let buf = base64 :: encode ( buf ) ; let res = format ! ( " " mime_type m data buf ) ; return res ; } src }
convert image source path to data uri scheme
if failed to read file, just return original src
convert image source path to data uri scheme if failed to read file just return original src
src
String