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

svg_metadata

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

10 releases

0.5.0 Sep 8, 2023
0.4.4 Feb 6, 2023
0.4.3 Aug 16, 2022
0.4.2 Dec 26, 2020
0.1.0 Aug 14, 2019

#347 in Multimedia

Download history 321/week @ 2023-12-13 384/week @ 2023-12-20 215/week @ 2023-12-27 346/week @ 2024-01-03 287/week @ 2024-01-10 224/week @ 2024-01-17 199/week @ 2024-01-24 214/week @ 2024-01-31 165/week @ 2024-02-07 280/week @ 2024-02-14 253/week @ 2024-02-21 270/week @ 2024-02-28 238/week @ 2024-03-06 293/week @ 2024-03-13 300/week @ 2024-03-20 360/week @ 2024-03-27

1,224 downloads per month

Apache-2.0/MIT

490KB
380 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–5MB
~76K SLoC