{"record":{"id":"6665f5d402c45e9f","repo":"getzola/zola","slug":"invalid-dimensions-svg-width-height-and-viewbox-n","errorCode":null,"errorMessage":"Invalid dimensions: SVG width/height and viewbox not set.","messagePattern":"Invalid dimensions: SVG width/height and viewbox not set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"components/imageproc/src/meta.rs","lineNumber":74,"sourceCode":"}\n\n#[derive(Debug, Serialize, Eq, PartialEq)]\npub struct ImageMetaResponse {\n    pub width: u32,\n    pub height: u32,\n    pub format: Option<&'static str>,\n    pub mime: Option<&'static str>,\n    pub description: Option<String>,\n    pub created: Option<String>,\n}\n\nimpl ImageMetaResponse {\n    fn new_svg(path: &Path) -> Result<Self> {\n        let img = SvgMetadata::parse_file(path)?;\n        let (w, h) = match (img.width(), img.height(), img.view_box()) {\n            (Some(w), Some(h), _) => Ok((w, h)),\n            (_, _, Some(view_box)) => Ok((view_box.width, view_box.height)),\n            _ => Err(anyhow!(\"Invalid dimensions: SVG width/height and viewbox not set.\")),\n        }?;\n        Ok(Self {\n            width: w as u32,\n            height: h as u32,\n            format: Some(\"svg\"),\n            mime: Some(\"text/svg+xml\"),\n            // SVG files have these fields, but we'd need a more comprehensive parser to read them.\n            description: None,\n            created: None,\n        })\n    }\n\n    fn new_avif(path: &Path) -> Result<Self> {\n        let avif_data = read_avif(&mut BufReader::new(fs::File::open(path)?))?;\n        let meta = avif_data.primary_item_metadata()?;\n        Ok(Self {\n            width: meta.max_frame_width.get(),\n            height: meta.max_frame_height.get(),","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/getzola/zola/blob/61d30828217957120309db657950224edf9707e2/components/imageproc/src/meta.rs#L56-L92","documentation":"`ImageMetaResponse::new_svg` extracts dimensions from an SVG file via SvgMetadata. An SVG can declare size via explicit width/height attributes, a viewBox, or neither (relying on CSS). When neither width/height nor a viewBox is present there is no intrinsic size, so the constructor fails with this error.","triggerScenarios":"Calling image metadata inspection (new_svg) on an .svg file whose root `<svg>` element has neither `width`/`height` attributes nor a `viewBox` attribute.","commonSituations":"Hand-authored or designer-exported SVGs sized purely with CSS (e.g. width:100%) or with percentage width/height only; icons generated by tools that omit viewBox; minified SVGs stripped of attributes.","solutions":["Add a `viewBox=\"0 0 W H\"` attribute to the SVG root element (preferred, keeps it responsive)","Or add explicit numeric `width` and `height` attributes to the `<svg>` element","If the file cannot be edited, replace it with a properly sized SVG"],"exampleFix":"// before\n<svg xmlns=\"http://www.w3.org/2000/svg\">\n// after\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">","handlingStrategy":"validation","validationCode":"import re\nSVG_VIEWBOX = re.compile(rb'viewBox\\s*=\\s*\"\\s*[\\d.]+[\\s,]+[\\d.]+[\\s,]+[\\d.]+[\\s,]+[\\d.]+')\nSVG_SIZE = re.compile(rb'<svg[^>]*\\swidth\\s*=')\ndef svg_has_dimensions(data: bytes) -> bool:\n    return bool(SVG_VIEWBOX.search(data) and (SVG_SIZE.search(data)))","typeGuard":"fn svg_is_sizable(root: &svg::node::element::SVG) -> bool {\n    root.get_attr(\"viewBox\").is_some()\n        || (root.get_attr(\"width\").is_some() && root.get_attr(\"height\").is_some())\n}","tryCatchPattern":"match ImageMetaResponse::new_svg(path) {\n    Ok(meta) => use_meta(meta),\n    Err(e) if e.to_string().contains(\"Invalid dimensions: SVG\") => {\n        log::warn!(\"{} lacks intrinsic size; skipping\", path.display());\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always include a viewBox on every SVG, even when sized via CSS","Lint SVG assets in CI for missing viewBox/width/height attributes","When exporting from design tools, enable 'responsive with viewBox' output options"],"tags":["svg","image-metadata","validation"],"backgroundTag":"missing-svg-dimensions","analyzedSha":"61d30828217957120309db657950224edf9707e2","analyzedAt":"2026-09-03T14:39:09.727Z","contentChangedAt":"2026-09-03T14:39:09.727Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}