SVG libraries for Go
Go has no SVG support in the standard library. The main options:
- canvas (
github.com/tdewolff/canvas) is a vector drawing library with many outputs: SVG, SVGZ, PDF, EPS, PNG, JPEG, WebP and more. It can also parse an SVG file into a canvas, so it converts SVG to PDF or PNG in pure Go. MIT, actively developed. - oksvg with its rasterizer rasterx renders SVG icons to an
image.RGBA. It handles paths, shapes, gradients and transforms but not text, filters, masks or most CSS. BSD-3-Clause; maintenance is slow. - SVGo (
github.com/ajstarks/svgo) generates SVG by calling a function per element, writing to anyio.Writer. Simple and stable, but licensed CC BY 4.0, a content license rather than an OSI software license.
For server-side conversion of arbitrary SVG files, calling rsvg-convert or resvg from Go gives more complete rendering than the pure Go libraries.
- canvas tdewolff/canvas is a Go vector graphics library that reads SVG and writes SVG, SVGZ, PDF and PNG. How to install it, convert SVG to PNG and PDF, draw shapes.
- oksvg oksvg is a pure Go SVG rasterizer for icons, built on rasterx. How to install it, render an SVG file to PNG, scale it to a target size.
- SVGo SVGo (ajstarks/svgo) generates SVG from Go code with one function per element. How to install it, write shapes, text, groups, paths and gradients.