Qu

load_svg

Builtin index · Images

result = load_svg(path)

Input: path · Output: result

What it is

Reads an SVG file back.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = load_svg(path)
path Record or Listnot documented yet
height —from the width/height attributes, falling back to the viewBox when those are absent or a percentage; absolute CSS units px/pt/pc/in/cm/mm are converted to user units
Returns a Record with fields width, height (from the width/height attributes, falling back to the viewBox when those are absent or a percentage; absolute CSS units px/pt/pc/in/cm/mm are converted to user units) and shapes, a List of shape records in document order. Reads the presentation attributes of rect, circle, line, path and text, descending into <g> groups. It does not apply transform=, resolve CSS (<style>, style=, class=), inherit styling from an ancestor group, or resolve <use>/<symbol>/gradients/patterns/masks/clip paths, and it skips <ellipse>/<polygon>/<polyline>/<image>. Unrecognized elements are skipped rather than rejected, so "loaded without error" does not mean "read everything in the file" — a round trip of a file save_svg wrote is exact, and that is the case it is built for. A file with no <svg> root is refused by name. Added in v0.3.0.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

import svg

shapes = [
  svg.rect(10, 10, 100, 50, fill = "#e74c3c"),
  svg.circle(200, 60, 40, fill = "#3498db", stroke = "#000000", stroke_width = 2),
  svg.line(0, 0, 300, 120, stroke = "#333333", stroke_width = 1.5),
  svg.path("M 10 100 L 60 40 L 110 100 Z", stroke = "#2ecc71", stroke_width = 2),
  svg.text(20, 150, "R&D output", font_size = 16, fill = "#111111")]

save_svg("drawing.svg", shapes, width = 320, height = 180)

doc = load_svg("drawing.svg")
print(doc.width)             # 320

print(len(doc.shapes))       # 5

print(doc.shapes[1].kind)    # circle

print(doc.shapes[1].r)       # 40

output
320
5
circle
40

from images