https://github.com/alipsa/gsvg
A Groovy object model for SVG (Scalar Vector Graphics)
https://github.com/alipsa/gsvg
Last synced: 5 months ago
JSON representation
A Groovy object model for SVG (Scalar Vector Graphics)
- Host: GitHub
- URL: https://github.com/alipsa/gsvg
- Owner: Alipsa
- License: mit
- Created: 2024-02-11T12:16:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-16T16:06:40.000Z (over 1 year ago)
- Last Synced: 2025-02-16T16:37:53.507Z (over 1 year ago)
- Language: Groovy
- Homepage:
- Size: 348 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://search.maven.org/artifact/se.alipsa.groovy/gsvg)
[](https://javadoc.io/doc/se.alipsa.groovy/gsvg)
# Groovy Scalar Vector Graphics (gsvg)
This is an object model to create, parse and manipulate SVG documents for groovy.
If you have groovy in your classpath, you can use it in any JVM language (Java, Scala, etc.).
The goal is to have a simple to use and lightweight library to create SVG documents programmatically or parse existing ones for modification. It supports the SVG 1.1 specification and the SVG 2 draft.
The jvm used should be java 17 or later.
See the test for various ways to create, parse and write SVG
to use it add the following to your Gradle build script
```groovy
implementation("org.apache.groovy:groovy:5.0.3")
implementation("se.alipsa.groovy:gsvg:0.9.0")
```
or if you prefer maven:
```xml
org.apache.groovy
groovy
5.0.3
se.alipsa.groovy
gsvg
0.9.0
```
## Quick start
Create an SVG in code:
```groovy
import se.alipsa.groovy.svg.Svg
import se.alipsa.groovy.svg.io.SvgWriter
def svg = new Svg(200, 120)
svg.addRect(180, 100).x(10).y(10).rx(12).ry(12).fill('#1976d2')
svg.addText('Hello SVG')
.x(30).y(70)
.fill('white')
.fontSize(24)
println SvgWriter.toXmlPretty(svg)
```
Read/parse an existing SVG file and change it:
```groovy
import se.alipsa.groovy.svg.io.SvgReader
import se.alipsa.groovy.svg.io.SvgWriter
import se.alipsa.groovy.svg.Rect
def svg = SvgReader.parse(new File('logo.svg'))
def rects = svg[Rect]
rects.each { it.stroke('red').strokeWidth(2) }
new File('logo-out.svg').text = SvgWriter.toXmlPretty(svg)
```
## Documentation
- [doc](doc/overview.md) for a simple overview of the library structure and usage examples.
- [javadoc](https://javadoc.io/doc/se.alipsa.groovy/gsvg) for full API documentation.
- [benchmarks](doc/benchmarks.md) for performance benchmarks and optimization tips.