An open API service indexing awesome lists of open source software.

https://github.com/twpayne/go-svg

Package svg provides convenience methods for creating and writing SVG documents.
https://github.com/twpayne/go-svg

go golang scalable-vector-graphics svg

Last synced: 8 months ago
JSON representation

Package svg provides convenience methods for creating and writing SVG documents.

Awesome Lists containing this project

README

          

# go-svg

[![PkgGoDev](https://pkg.go.dev/badge/github.com/twpayne/go-svg)](https://pkg.go.dev/github.com/twpayne/go-svg)

Package `svg` provides convenience methods for creating and writing SVG documents.

## Key Features

* Fluent API for building arbitrarily complex SVG documents.
* Support for all SVG elements.
* Support for all SVG units.
* Compatibility with the standard library's [`encoding/xml`](https://pkg.go.dev/encoding/xml) package.
* Simple mapping between functions and SVG elements.

## Example

```go
func ExampleNew() {
svgElement := svg.New().WidthHeight(4, 4, svg.CM).ViewBox(0, 0, 400, 400).AppendChildren(
svg.Title(svg.CharData("Example triangle01- simple example of a 'path'")),
svg.Desc(svg.CharData("A path that draws a triangle")),
svg.Rect().XYWidthHeight(1, 1, 398, 398, svg.Number).Fill("none").Stroke("blue"),
svg.Path().D(svgpath.New().
MoveToAbs([]float64{100, 100}).
LineToAbs([]float64{300, 100}).
LineToAbs([]float64{200, 300}).
ClosePath(),
)).Fill("red").Stroke("blue").StrokeWidth(svg.Number(3)),
)
if _, err := svgElement.WriteToIndent(os.Stdout, "", " "); err != nil {
panic(err)
}
}
```

Output:

```xml

Example triangle01- simple example of a 'path'
A path that draws a triangle

```

![Output](testdata/triangle01.svg)

## License

MIT