text2img
text2img copied to clipboard
text2img is a go (golang) package which lets you generate an image from a text. It's especially useful to generate OG images.
text2img
package text2img
lets you generate an image from a text. It's especially useful to generate OG images.
Installation
Binary
If you use text2img
from your command line, install the binary from releases.
Or use go get
:
go get github.com/Iwark/text2img/cmd/text2img
Go code
If you use text2img
from your go code, install the package by go get
.
$ go get github.com/Iwark/text2img
Usage
Binary
When using a random color background image:
$ text2img -fontpath="fonts/font.ttf" -output="test.jpg" -text="text2img generates the image from a text"
Using a specific image file:
$ text2img -fontpath="fonts/font.ttf" -output="test.jpg" -text="text2img generates the image from a text" -bgimg="gophers.jpg"
(The Go gopher was designed by Renée French.)
Go code
You can use this package as follows:
package main
import (
"image/jpeg"
"os"
"github.com/Iwark/text2img"
)
func main() {
path := "fonts/font.ttf"
d, err := text2img.NewDrawer(text2img.Params{
FontPath: path,
})
checkError(err)
img, err := d.Draw("text2img generates the image from a text")
checkError(err)
file, err := os.Create("test.jpg")
checkError(err)
defer file.Close()
err = jpeg.Encode(file, img, &jpeg.Options{Quality: 100})
checkError(err)
}
More usage can be found at the godoc.
License
This package is released under the MIT License.