Golang: print text on image

I am trying to use the following packages

"image/draw" "image" "image/jpeg" 

but I want to be able to print any text or numbers (which may also be texts) in my image.

But it does not look out of the box in Go to do this.

Can someone help me with the GO way solution for this?

+7
text image go
source share
2 answers

I found only this one, freetype-go

Is there a better and only library for my needs?

+8
source share

check this

 package main import ( "github.com/fogleman/gg" "log" ) func main() { const S = 1024 im, err := gg.LoadImage("src.jpg") if err != nil { log.Fatal(err) } dc := gg.NewContext(S, S) dc.SetRGB(1, 1, 1) dc.Clear() dc.SetRGB(0, 0, 0) if err := dc.LoadFontFace("/Library/Fonts/Arial.ttf", 96); err != nil { panic(err) } dc.DrawStringAnchored("Hello, world!", S/2, S/2, 0.5, 0.5) dc.DrawRoundedRectangle(0, 0, 512, 512, 0) dc.DrawImage(im, 0, 0) dc.DrawStringAnchored("Hello, world!", S/2, S/2, 0.5, 0.5) dc.Clip() dc.SavePNG("out.png") } 
+1
source share

All Articles