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.
- Host: GitHub
- URL: https://github.com/twpayne/go-svg
- Owner: twpayne
- License: mit
- Created: 2024-05-06T21:29:12.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T20:59:10.000Z (over 1 year ago)
- Last Synced: 2025-04-11T19:23:05.133Z (about 1 year ago)
- Topics: go, golang, scalable-vector-graphics, svg
- Language: Go
- Homepage:
- Size: 127 KB
- Stars: 21
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```

## License
MIT