resvg

package module
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 12 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

resvg

resvg is a wrapper around rust's resvg c-api crate, used by usql to render SVGs. Useful for rendering SVGs.

Overview | Building Artifacts | Documents | TODO | About

Unit Tests Go Reference Discord Discussion

Overview

Install in the usual Go fashion:

$ go get github.com/xo/resvg@latest

Then use like the following:

package resvg_test

import (
	"bytes"
	"fmt"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func Example() {
	img, err := resvg.Render(svgData)
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
	// Output:
	// width: 400 height: 180
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Using on Windows

When using this library with Windows, the Go binary must be built statically:

$ go build -ldflags '-extldflags "-static"'

Otherwise, the resvg.dll (not included) will need to be located next to the built Go binary, or in the Windows system path.

The windows/arm64 archive is built for the aarch64-pc-windows-gnullvm target. Build with a clang based C compiler, such as llvm-mingw, because the archive needs libunwind.

Using on FreeBSD

The freebsd/amd64 archive links the FreeBSD base libraries libexecinfo, libkvm, libmemstat, libprocstat, libdevstat and libgcc_s. All of them ship with FreeBSD. Nobody has run the package on FreeBSD yet. See docs/BACKLOG.md.

Using on Alpine (musl)

Pass -tags musl when building for linux/amd64 or linux/arm64 on a musl-based distribution such as Alpine, and have libunwind-dev (or your distribution's equivalent) installed at link time:

$ go build -tags musl

See libresvg/README.md for why this needs a separate target and can't be automatic.

Building Artifacts

Notes for building the libresvg artifacts:

Using gen.sh

Build Darwin images:

# get cross
$ git clone https://github.com/cross-rs/cross.git
$ git -C cross submodule update --init --remote

# grab sdk
$ export SDK='https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz'
$ curl -L -o cross/docker/$(basename "$SDK") "$SDK"
$ md5sum cross/docker/MacOSX11.3.sdk.tar.xz
22c0ed904531f6d7dee4f87c15f7cf47  cross/docker/MacOSX11.3.sdk.tar.xz

# build containers (from cross directory, make sure the sdk file is in the cross/docker directory)
$ cd cross

# -----------------------------------------------------------------------------------
# from the ~/src/cross directory:
#
# 1. update docker/cross-toolchains/docker/Dockerfile.{x86_64,aarch64}-apple-darwin-cross
#    to use the latest ubuntu:24.04 image, or use the base image the other base
#    cross-rs images are using:
#
#      perl -pi -e 's/FROM ubuntu:.*/FROM ubuntu:24.04/' docker/cross-toolchains/docker/Dockerfile.{x86_64,aarch64}-apple-darwin-cross
#
# 2. change the llvm version used in the darwin.sh script:
#
#      perl -pi -e 's/install_llvm 16/install_llvm 22/' docker/cross-toolchains/docker/darwin.sh
# -----------------------------------------------------------------------------------

$ CROSS_CONTAINER_ENGINE_NO_BUILDKIT=1 cargo build-docker-image x86_64-apple-darwin-cross  --build-arg 'MACOS_SDK_FILE=MacOSX11.3.sdk.tar.xz'
$ CROSS_CONTAINER_ENGINE_NO_BUILDKIT=1 cargo build-docker-image aarch64-apple-darwin-cross --build-arg 'MACOS_SDK_FILE=MacOSX11.3.sdk.tar.xz'

# add rust toolchains
$ rustup target add x86_64-apple-darwin
$ rustup target add aarch64-apple-darwin

Then use:

$ ./gen.sh

This also (re)writes the go.mod/doc.go/lib.go files under libresvg/<target>/ and the root link_GOOS_GOARCH.go files -- one Go module per platform, so a build only downloads the archive for the platform it targets. See libresvg/README.md for why, and for ./gen.sh -m to regenerate just that scaffolding without a rebuild.

Manually
$ mkdir -p libresvg/$(go env GOOS)_$(go env GOARCH)
$ git clone https://github.com/linebender/resvg.git && cd resvg/crates/c-api
$ cargo build --release
$ cp ../../target/release/libresvg.a ../../../libresvg/$(go env GOOS)_$(go env GOARCH)
$ cd ../../../ && rm -rf resvg
$ ./gen.sh -m -t $(go env GOOS)_$(go env GOARCH)

To get the needed static dependencies (for Windows or other platforms):

$ cd resvg/crates/c-api
$ RUSTFLAGS="--print=native-static-libs" cargo build --release

Use

Documents

  • AGENTS.md holds the rules for a coding agent: the layout, the conventions and the commands that test the code. CLAUDE.md imports it.
  • CONTRIBUTING.md is for a person who changes the project, and says how to install the agent skills.
  • docs/PLAN.md holds the plan, every decision, and the open questions.
  • docs/BACKLOG.md holds the work that is known and not done.
  • libresvg/README.md says why each platform archive is a module of its own, and how to release one.

TODO

  • Rewrite as pure Go

About

resvg was written primarily to support these projects:

  • vegagoja - a package to render Vega visualizations
  • usql - a universal command-line interface for SQL databases

Documentation

Overview

Package resvg is a wrapper around rust's resvg c-api crate.

The archives are prebuilt and come from a companion module per platform, under github.com/xo/resvg/libresvg/. Each is pulled in by a build-tagged blank import in link_GOOS_GOARCH.go, so `go build` downloads only the one for the platform being built and the #cgo LDFLAGS live next to the archive they describe, in that module's lib.go. See libresvg/README.md.

Example
package main

import (
	"bytes"
	"fmt"
	"image"
	"image/png"
	"log"
	"os"
)

func main() {
	img, _, err := image.Decode(bytes.NewReader(svgData))
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d\n", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Output:
width: 400 height: 180
Example (Background)
package main

import (
	"bytes"
	"fmt"
	"image/color"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func main() {
	img, err := resvg.Render(svgData, resvg.WithBackground(color.White))
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d\n", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect_white.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Output:
width: 400 height: 180
Example (Distort)
package main

import (
	"bytes"
	"fmt"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func main() {
	img, err := resvg.Render(svgData, resvg.WithWidth(200), resvg.WithHeight(700))
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d\n", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect_distort.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Output:
width: 200 height: 700
Example (Fonts)

Example_fonts renders an SVG containing text using a specific, embedded font rather than whatever happens to be installed on the system. Load a font file (or use WithFonts for in-memory font data), disable system fonts so the loaded one is actually used, and map any generic CSS family name the SVG's text uses (here, "sans-serif") to it -- without that mapping, text set to a generic family won't resolve to a specific loaded font just because system fonts are off.

package main

import (
	"bytes"
	"fmt"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func main() {
	img, err := resvg.Render(svgDataText,
		resvg.WithLoadSystemFonts(false),
		resvg.WithFontFiles("testdata/fonts/DejaVuSans.ttf"),
		resvg.WithSansSerifFamily("DejaVu Sans"),
	)
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d\n", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("text.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgDataText = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="300" height="60" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <text x="10" y="40" font-family="sans-serif" font-size="24">Hello, resvg!</text>
</svg>`)
Output:
width: 300 height: 60
Example (Render)
package main

import (
	"bytes"
	"fmt"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func main() {
	img, err := resvg.Render(svgData)
	if err != nil {
		log.Fatal(err)
	}
	b := img.Bounds()
	fmt.Printf("width: %d height: %d\n", b.Max.X, b.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, img); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect_render.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Output:
width: 400 height: 180
Example (ScaleBestFit)
package main

import (
	"bytes"
	"fmt"
	"image/png"
	"log"
	"os"

	"github.com/xo/resvg"
)

func main() {
	a, err := resvg.Render(svgData, resvg.WithScaleMode(resvg.ScaleBestFit), resvg.WithWidth(300))
	if err != nil {
		log.Fatal(err)
	}
	ab := a.Bounds()
	fmt.Printf("width: %d height: %d\n", ab.Max.X, ab.Max.Y)
	buf := new(bytes.Buffer)
	if err := png.Encode(buf, a); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect_bestfit_a.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
	b, err := resvg.Render(svgData, resvg.WithScaleMode(resvg.ScaleBestFit), resvg.WithHeight(135))
	if err != nil {
		log.Fatal(err)
	}
	bb := b.Bounds()
	fmt.Printf("width: %d height: %d\n", bb.Max.X, bb.Max.Y)
	buf.Reset()
	if err := png.Encode(buf, b); err != nil {
		log.Fatal(err)
	}
	if err := os.WriteFile("rect_bestfit_b.png", buf.Bytes(), 0o644); err != nil {
		log.Fatal(err)
	}
}

var svgData = []byte(`<?xml version="1.0" encoding="iso-8859-1"?>
<svg width="400" height="180" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <rect x="50" y="20" width="150" height="150" style="fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" />
  Sorry, your browser does not support inline SVG.
</svg>`)
Output:
width: 300 height: 135
width: 300 height: 135

Index

Examples

Constants

This section is empty.

Variables

View Source
var Default = New()

Default is the default renderer.

Functions

func Decode added in v0.3.0

func Decode(r io.Reader) (image.Image, error)

Decode decodes a svg from the reader.

func DecodeConfig added in v0.3.0

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig decodes a svg config from the reader.

func Render

func Render(data []byte, opts ...Option) (*image.RGBA, error)

Render renders svg data as a RGBA image.

func Version added in v0.2.2

func Version() string

Version returns the resvg version.

Types

type ErrNo added in v0.6.0

type ErrNo int

ErrNo wraps a resvg error.

func (ErrNo) Error added in v0.6.0

func (err ErrNo) Error() string

Error satisfies the [error] interface.

type Error added in v0.6.0

type Error string

Error is a package error.

const (
	ErrClosed               Error = "closed"
	ErrInvalidWidthOrHeight Error = "invalid width or height"
	ErrInvalidWidth         Error = "invalid width"
	ErrInvalidHeight        Error = "invalid height"
	ErrInvalidXScale        Error = "invalid x scale"
	ErrInvalidYScale        Error = "invalid y scale"
)

Errors.

func (Error) Error added in v0.6.0

func (err Error) Error() string

Error satisfies the [error] interface.

type ImageRendering added in v0.2.0

type ImageRendering int

ImageRendering is the image rendering mode.

const (
	ImageRenderingOptimizeQuality ImageRendering = C.RESVG_IMAGE_RENDERING_OPTIMIZE_QUALITY
	ImageRenderingOptimizeSpeed   ImageRendering = C.RESVG_IMAGE_RENDERING_OPTIMIZE_SPEED
)

Image rendering modes.

type Option added in v0.2.0

type Option func(*Resvg)

Option is a resvg rendering option.

func WithBackground added in v0.2.3

func WithBackground(background color.Color) Option

WithBackground is a resvg option to set the fill background color.

func WithCursiveFamily added in v0.2.0

func WithCursiveFamily(cursiveFamily string) Option

WithCursiveFamily is a resvg option to set the cursive family.

func WithDPI added in v0.2.0

func WithDPI(dpi float32) Option

WithDPI is a resvg option to set the DPI.

func WithFantasyFamily added in v0.2.0

func WithFantasyFamily(fantasyFamily string) Option

WithFantasyFamily is a resvg option to set the fantasy family.

func WithFontFamily added in v0.2.0

func WithFontFamily(fontFamily string) Option

WithFontFamily is a resvg option to set the font family.

func WithFontFiles added in v0.2.0

func WithFontFiles(fontFiles ...string) Option

WithFontFiles is a resvg option to set font files.

func WithFontSize added in v0.2.0

func WithFontSize(fontSize float32) Option

WithFontSize is a resvg option to set the font size.

func WithFonts added in v0.2.0

func WithFonts(fonts ...[]byte) Option

WithFonts is a resvg option to set font data.

func WithHeight added in v0.5.0

func WithHeight(height int) Option

WithHeight is a resvg option to set the height.

func WithImageRendering added in v0.2.0

func WithImageRendering(imageRendering ImageRendering) Option

WithImageRendering is a resvg option to set the image rendering mode.

func WithLanguages added in v0.2.0

func WithLanguages(languages ...string) Option

WithLanguages is a resvg option to set the languages.

func WithLoadSystemFonts added in v0.2.0

func WithLoadSystemFonts(loadSystemFonts bool) Option

WithLoadSystemFonts is a resvg option to load system fonts.

func WithMonospaceFamily added in v0.2.0

func WithMonospaceFamily(monospaceFamily string) Option

WithMonospaceFamily is a resvg option to set the monospace family.

func WithResourcesDir added in v0.2.0

func WithResourcesDir(resourcesDir string) Option

WithResourcesDir is a resvg option to set the resources dir.

func WithSansSerifFamily added in v0.10.0

func WithSansSerifFamily(sansSerifFamily string) Option

WithSansSerifFamily is a resvg option to set the sans-serif family.

func WithScaleMode added in v0.6.0

func WithScaleMode(scaleMode ScaleMode) Option

WithScaleMode is a resvg option to set scale mode.

func WithSerifFamily added in v0.2.0

func WithSerifFamily(serifFamily string) Option

WithSerifFamily is a resvg option to set the serif family.

func WithShapeRendering added in v0.2.0

func WithShapeRendering(shapeRendering ShapeRendering) Option

WithShapeRendering is a resvg option to set the shape rendering mode.

func WithStylesheet added in v0.7.0

func WithStylesheet(stylesheet string) Option

WithStylesheet is a resvg option to set the stylesheet.

func WithTextRendering added in v0.2.0

func WithTextRendering(textRendering TextRendering) Option

WithTextRendering is a resvg option to set the text rendering mode.

func WithTransform added in v0.5.0

func WithTransform(a, b, c, d, e, f float32) Option

WithTransform is a resvg option to set the transform used.

func WithWidth added in v0.5.0

func WithWidth(width int) Option

WithWidth is a resvg option to set the width.

type Resvg added in v0.2.0

type Resvg struct {
	// contains filtered or unexported fields
}

Resvg wraps the resvg c-api to render svgs as standard a image.RGBA.

A Resvg's configuration is fixed by the Option values passed to New and never changes afterward: there is no method to alter it once created. That makes a *Resvg, including the package-level Default, safe to share across goroutines -- concurrent calls to Parse, Render, and ParseConfig only read the underlying C options, never write them, and resvg's C API supports parsing and rendering concurrently against the same, unmodified resvg_options. Close is the only method that mutates a Resvg. It is safe to call concurrently with the others: it blocks until any in-flight call completes, releases the C options, and causes every call afterward to return ErrClosed.

Default must not be closed: it backs the package-level Render, Decode, and DecodeConfig, and the image.Format handlers registered for "svg". Closing it breaks every caller of those for the remainder of the process.

func New added in v0.2.0

func New(opts ...Option) *Resvg

New creates a new resvg, applying opts and building its underlying C options immediately. The returned Resvg's configuration cannot be changed afterward; construct a new one with different opts instead.

func (*Resvg) Close added in v0.9.0

func (r *Resvg) Close() error

Close releases the C resources associated with r. Safe to call more than once, and safe to call concurrently with Parse, Render, and ParseConfig: it blocks until any of those already in flight complete. Every call to r, and to any Tree already obtained from r, returns ErrClosed afterward.

func (*Resvg) Parse added in v0.9.0

func (r *Resvg) Parse(data []byte) (*Tree, error)

Parse parses svg data into a Tree using r's options. Parsing is the expensive part of rendering an SVG; keeping the returned Tree around lets a caller call Config and Render more than once without reparsing data. The Tree must be released with Close once it is no longer needed.

func (*Resvg) ParseConfig added in v0.3.0

func (r *Resvg) ParseConfig(data []byte) (image.Config, error)

ParseConfig parses the svg, returning an image config.

func (*Resvg) Render added in v0.2.0

func (r *Resvg) Render(data []byte) (*image.RGBA, error)

Render renders svg data as a RGBA image.

type ScaleMode added in v0.6.0

type ScaleMode uint8

ScaleMode is a scale mode.

const (
	ScaleNone ScaleMode = iota
	ScaleMinWidth
	ScaleMinHeight
	ScaleMaxWidth
	ScaleMaxHeight
	ScaleBestFit
)

Scale modes.

func (ScaleMode) Scale added in v0.6.0

func (mode ScaleMode) Scale(width, height, w, h uint) (int, int, float32, float32)

Scale calculates the scale for the width, height.

type ShapeRendering added in v0.2.0

type ShapeRendering int

ShapeRendering is the shape rendering mode.

const (
	ShapeRenderingOptimizeSpeed      ShapeRendering = C.RESVG_SHAPE_RENDERING_OPTIMIZE_SPEED
	ShapeRenderingCrispEdges         ShapeRendering = C.RESVG_SHAPE_RENDERING_CRISP_EDGES
	ShapeRenderingGeometricPrecision ShapeRendering = C.RESVG_SHAPE_RENDERING_GEOMETRIC_PRECISION
)

Shape rendering modes.

type TextRendering added in v0.2.0

type TextRendering int

TextRendering is the text rendering mode.

const (
	TextRenderingOptimizeSpeed      TextRendering = C.RESVG_TEXT_RENDERING_OPTIMIZE_SPEED
	TextRenderingOptimizeLegibility TextRendering = C.RESVG_TEXT_RENDERING_OPTIMIZE_LEGIBILITY
	TextRenderingGeometricPrecision TextRendering = C.RESVG_TEXT_RENDERING_GEOMETRIC_PRECISION
)

Text rendering modes.

type Tree added in v0.9.0

type Tree struct {
	// contains filtered or unexported fields
}

Tree is an SVG parsed by Resvg.Parse. Parsing is independent of the scaling, background, and transform used to render it, so the same Tree can be rendered more than once -- via repeated calls to Render or Config -- without reparsing the source data. A Tree must be released with Close once it is no longer needed; a finalizer releases it otherwise, but that is not guaranteed to run promptly.

A Tree is tied to the Resvg that parsed it and reads that Resvg's Width, Height, ScaleMode, Background, and Transform each time Config or Render is called, so changing which Resvg produced it is not possible, but the caller can rely on those values as of the current Resvg -- they cannot change after New. Concurrent calls to Config and Render on the same Tree from multiple goroutines are safe; Close is safe to call concurrently with them and blocks until any in-flight call completes.

func (*Tree) Close added in v0.9.0

func (t *Tree) Close() error

Close releases the C resources associated with t. Safe to call more than once, and safe to call concurrently with Config and Render: it blocks until any of those already in flight complete. Every call to t returns ErrClosed afterward.

func (*Tree) Config added in v0.9.0

func (t *Tree) Config() (image.Config, error)

Config returns the tree's scaled image dimensions, using t.r's current Width, Height, and ScaleMode.

func (*Tree) Render added in v0.9.0

func (t *Tree) Render() (*image.RGBA, error)

Render renders the tree as an RGBA image, using t.r's current Width, Height, ScaleMode, Background, and Transform.

Directories

Path Synopsis
libresvg
darwin_amd64 module
darwin_arm64 module
freebsd_amd64 module
linux_amd64 module
linux_arm module
linux_arm64 module
windows_amd64 module
windows_arm64 module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL