-
-
Notifications
You must be signed in to change notification settings - Fork 104
Getting Started
Taco de Wolff edited this page Apr 5, 2021
·
12 revisions
- Git: https://git-scm.com/
- Go (at least v1.13): https://golang.org/doc/install
If you need advanced script support for text rendering (such as Arabic, Hebrew, Asian languages, ...) you will also need:
- HarfBuzz: https://harfbuzz.github.io/install-harfbuzz.html
- FriBidi: https://github.com/fribidi/fribidi
Create a new project that will be using the canvas library:
mkdir project
cd project
export GO111MODULE=on
go mod init main
go get -u github.com/tdewolff/canvas
Create main.go
with the following contents:
package main
import (
"github.com/tdewolff/canvas"
"github.com/tdewolff/canvas/rasterizer"
)
func main() {
// Create new canvas of dimension 100x100 mm
c := canvas.New(100, 100)
// Create a canvas context used to keep drawing state
ctx := canvas.NewContext(c)
// Create a triangle path from an SVG path and draw it to the canvas
triangle := canvas.ParseSVG("L60 0L30 60z")
ctx.DrawPath(20, 20, triangle)
// Rasterize the canvas and write to a PNG file with 3.2 dots-per-mm (320x320 px)
c.WriteFile("project.png", rasterizer.PNGWriter(3.2))
}
We run the basic template which will output a file project.png
.
go run main.go