Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

dennwc/gotrace

Repository files navigation

GoTrace

WARNING: This library is deprecated in favor of gotranspile/gotrace. It will not receive any updates.

Pure Go implementation of Potrace vectorization library. Supports simple SVG output generation.

Also includes cgo bindings for the original Potrace library.

Original image

Original

Vectorized image

Vectorized

Installation

go get github.com/dennwc/gotrace

Usage

Process image with an alpha channel, generate SVG:

bm := gotrace.NewBitmapFromImage(img, nil)
paths, _ := gotrace.Trace(bm, nil)
gotrace.WriteSvg(file, img.Bounds(), paths, "")

Custom threshold function:

bm := gotrace.NewBitmapFromImage(img, func(x, y int, c color.Color) bool {
    r, g, b, _ := c.RGBA()
    return r + g + b > 128
})
paths, _ := gotrace.Trace(bm, nil)