Pure Go implementation of Potrace vectorization library. Supports SVG, PDF and DXF output generation.
It is a direct machine translation (transpilation) of potrace using cxgo.
Original image
Vectorized image
go install github.com/gotranspile/gotrace@latest
Convert PNG image to SVG:
gotrace -s -o ./testdata/stanford.svg ./testdata/stanford.png
go get -u github.com/gotranspile/gotrace
Minimal example:
func traceImage(outPath string, img image.Image) error {
bm := gotrace.BitmapFromImage(img, nil)
paths, err := gotrace.Trace(bm, nil)
if err != nil {
return err
}
sz := img.Bounds().Size()
return gotrace.RenderFile("svg", nil, outPath, paths, sz.X, sz.Y)
}
For a full example, see example_test.go.
This library uses cxgo
to translate C source code directly to Go. See cxgo.yml for the config.
To regenerate source, install cxgo
and goimports
and run:
go generate