मुख्य सामग्री पर जाएँ

raygeo.svg.metadata

SVG metadata extraction.

Extracts width, height, units and viewBox values from the root element of an SVG document.

SvgMetadata​

SVG document metadata extracted from an SVG string.

Provides width, height, units and viewBox values parsed from the root <svg> element.

height​

height: Optional[float]

Document height as a numeric value (may be None if not set).

height_unit​

height_unit: str

Unit string for the height attribute.

viewbox​

viewbox: Optional[tuple[float, float, float, float]]

ViewBox as (min_x, min_y, width, height), or None.

width​

width: Optional[float]

Document width as a numeric value (may be None if not set).

width_unit​

width_unit: str

Unit string for the width attribute (e.g. "mm", "in", "px").

height_mm()​

height_mm(dpi: float = 96.0) -> Optional[float]

Convert the document height to millimetres.

ParameterTypeDescription
dpifloat = 96.0Pixels-per-inch for px/unitless conversion (default 96).
ReturnsOptional[float]Height in millimetres, or None if not set.
ComplexityO(1)

height_px()​

height_px(dpi: float = 96.0) -> Optional[float]

Convert the document height to pixels.

ParameterTypeDescription
dpifloat = 96.0Pixels-per-inch for conversion (default 96).
ReturnsOptional[float]Height in pixels, or None if not set.
ComplexityO(1)

width_mm()​

width_mm(dpi: float = 96.0) -> Optional[float]

Convert the document width to millimetres.

ParameterTypeDescription
dpifloat = 96.0Pixels-per-inch for px/unitless conversion (default 96).
ReturnsOptional[float]Width in millimetres, or None if not set.
ComplexityO(1)

width_px()​

width_px(dpi: float = 96.0) -> Optional[float]

Convert the document width to pixels.

ParameterTypeDescription
dpifloat = 96.0Pixels-per-inch for conversion (default 96).
ReturnsOptional[float]Width in pixels, or None if not set.
ComplexityO(1)

Functions​

extract_svg_metadata()​

extract_svg_metadata(svg_str: str) -> SvgMetadata

Extract width, height, units and viewBox from an SVG string.

ParameterTypeDescription
svg_strstrSVG document as a string.
ReturnsSvgMetadataSvgMetadata instance with width, height, width_unit, height_unit, and viewbox attributes.
ComplexityO(n) where n = size of SVG document