I'm trying to use next packages
"image/draw"
"image"
"image/jpeg"
but I want to have possibility to print any text or numbers (which may also be text) in the my image.
But it looks like nothing from the box in Go to do this.
Can anyone help me with "GO way" solution for this?
The fmt.print () function in Go language formats using the default formats for its operands and writes to standard output. Here Spaces are added between operands when any string is not used as a parameter. Moreover, this function is defined under the fmt package.
The golang.org/x/image/font package just defines interfaces for font faces and drawing text on images. You may use the Go implementation of Freetype font rasterizer: github.com/golang/freetype. The key type is freetype.Context, it has all the methods you need. For a complete example, check out this file: example/freetype/main.go.
png – png implements a PNG image decoder and encoder. So we’ll dive into the png library, and the rest are just similar implementations for various formats. GoLang png package implements a PNG image decoder and encoder. A wonderful implementation of converting an image from base64 string to png, and then printing it with 5 levels of lines:
The fmt.print () function in Go language formats using the default formats for its operands and writes to standard output. Here Spaces are added between operands when any string is not used as a parameter.
I found just this one, freetype-go
is there a best and only lib for my needs?
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With