Add gofont.go example, close #45

This commit is contained in:
Michael Fogleman 2018-08-22 21:57:45 -04:00
parent 7cc16ce8b2
commit 0e0ff3ade7

26
examples/gofont.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"log"
"github.com/fogleman/gg"
"github.com/golang/freetype/truetype"
"golang.org/x/image/font/gofont/goregular"
)
func main() {
font, err := truetype.Parse(goregular.TTF)
if err != nil {
log.Fatal(err)
}
face := truetype.NewFace(font, &truetype.Options{Size: 48})
dc := gg.NewContext(1024, 1024)
dc.SetFontFace(face)
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
dc.DrawStringAnchored("Hello, world!", 512, 512, 0.5, 0.5)
dc.SavePNG("out.png")
}