fn image_dimensions(path: &PathBuf) -> Result<(u32, u32)> {
    if let Some("svg") = path.extension().and_then(OsStr::to_str) {
        let img = svg::Metadata::parse_file(&path)
            .map_err(|e| Error::chain(format!("Failed to process SVG: {}", path.display()), e))?;
        match (img.height(), img.width(), img.view_box()) {
            (Some(h), Some(w), _) => Ok((h as u32, w as u32)),
            (_, _, Some(view_box)) => Ok((view_box.height as u32, view_box.width as u32)),
            _ => Err("Invalid dimensions: SVG width/height and viewbox not set.".into()),
        }
    } else {
        let img = image::open(&path)
            .map_err(|e| Error::chain(format!("Failed to process image: {}", path.display()), e))?;
        Ok((img.height(), img.width()))
    }
}
// Try to read the image dimensions for a given image
Try to read the image dimensions for a given image
Try to read the image dimensions for a given image
fn image_dimensions(path: &PathBuf) -> Result<(u32, u32)> {
    if let Some("svg") = path.extension().and_then(OsStr::to_str) {
        let img = svg::Metadata::parse_file(&path)
            .map_err(|e| Error::chain(format!("Failed to process SVG: {}", path.display()), e))?;
        match (img.height(), img.width(), img.view_box()) {
            (Some(h), Some(w), _) => Ok((h as u32, w as u32)),
            (_, _, Some(view_box)) => Ok((view_box.height as u32, view_box.width as u32)),
            _ => Err("Invalid dimensions: SVG width/height and viewbox not set.".into()),
        }
    } else {
        let img = image::open(&path)
            .map_err(|e| Error::chain(format!("Failed to process image: {}", path.display()), e))?;
        Ok((img.height(), img.width()))
    }
}
fn image_dimensions ( path : & PathBuf ) -> Result < ( u32 , u32 ) > { if let Some ( " " ) = path . extension ( ) . and_then ( OsStr :: to_str ) { let img = svg :: Metadata :: parse_file ( & path ) . map_err ( | e | Error :: chain ( format ! ( " " path display ( ) ) , e ) ) ? ; match ( img . height ( ) , img . width ( ) , img . view_box ( ) ) { ( Some ( h ) , Some ( w ) , _ ) => Ok ( ( h as u32 , w as u32 ) ) , ( _ , _ , Some ( view_box ) ) => Ok ( ( view_box . height as u32 , view_box . width as u32 ) ) , _ => Err ( " " . into ( ) ) , } } else { let img = image :: open ( & path ) . map_err ( | e | Error :: chain ( format ! ( " " path display ( ) ) , e ) ) ? ; Ok ( ( img . height ( ) , img . width ( ) ) ) } }
Try to read the image dimensions for a given image
Try to read the image dimensions for a given image
path
&PathBuf
path
&PathBuf