gg/examples/gofont.go

27 lines
493 B
Go
Raw Permalink Normal View History

2018-08-23 03:57:45 +02:00
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")
}