You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a new project that will be using the canvas library:
mkdir project
cd project
go mod init
go get -u github.com/tdewolff/canvas
Basic template
Create main.go with the following contents:
package main
import (
"github.com/tdewolff/canvas""github.com/tdewolff/canvas/renderers"
)
funcmain() {
// Create new canvas of dimension 100x100 mmc:=canvas.New(100, 100)
// Create a canvas context used to keep drawing statectx:=canvas.NewContext(c)
// Create a triangle path from an SVG path and draw it to the canvastriangle, err:=canvas.ParseSVGPath("L60 0L30 60z")
iferr!=nil {
panic(err)
}
ctx.SetFillColor(canvas.Mediumseagreen)
ctx.DrawPath(20, 20, triangle)
// Rasterize the canvas and write to a PNG file with 3.2 dots-per-mm (320x320 px)iferr:=renderers.Write("getting-started.png", c, canvas.DPMM(3.2)); err!=nil {
panic(err)
}
}
Run
We run the basic template which will output a file getting-started.png.