#svg #width-height #metadata #graphics #image #file-metadata

svg_metadata

Extracts metadata (like the viewBox, width, and height) from SVG graphics

11 releases

0.5.1 May 28, 2024
0.5.0 Sep 8, 2023
0.4.4 Feb 6, 2023
0.4.3 Aug 16, 2022
0.3.0 Aug 24, 2019

#342 in Parser implementations

Download history 291/week @ 2024-07-24 268/week @ 2024-07-31 315/week @ 2024-08-07 386/week @ 2024-08-14 244/week @ 2024-08-21 288/week @ 2024-08-28 341/week @ 2024-09-04 273/week @ 2024-09-11 848/week @ 2024-09-18 638/week @ 2024-09-25 433/week @ 2024-10-02 534/week @ 2024-10-09 261/week @ 2024-10-16 197/week @ 2024-10-23 224/week @ 2024-10-30 252/week @ 2024-11-06

1,014 downloads per month

Apache-2.0/MIT

490KB
384 lines

svg-metadata

CI Documentation

What is it?

This crate extracts metadata from SVG files. Currently it reads the following attributes:

  • viewBox
  • width
  • height

You can add more!

Usage Example

use svg_metadata::{Metadata, ViewBox};

fn main() {
    let svg = r#"
        <svg viewBox="0 1 99 100" xmlns="http://www.w3.org/2000/svg">
            <rect x="0" y="0" width="100%" height="100%"/>
        </svg>
    "#;

    let meta = Metadata::parse(svg).unwrap();
    assert_eq!(
        meta.view_box,
        Some(ViewBox {
            min_x: 0.0,
            min_y: 1.0,
            width: 99.0,
            height: 100.0
        })
    );
}

(You can also parse files directly with parse_file().)

Credits

The SVG fixtures used for testing are provided by

under their respective licenses.

Dependencies

~2.3–3.5MB
~59K SLoC