Writer is a simple and easy-to-use package to write any text on images. It uses harfbuzz for shaping and also works totally fine on bi-directional texts.
[!NOTE] Writer is currently work-in-progress and also looking for feedback.
To get started using Writer, you should first have the latest version of Harfbuzz installed on your machine. You also need pkg-config for go-harfbuzz.
go get github.com/haashemi/writer@main
There are a few examples in the examples folder, but here's one:
package main
import (
"image"
"image/png"
"os"
"github.com/haashemi/writer"
)
func main() {
// Load face from the font file
face := writer.NewFaceFromFile("./fonts/Vazirmatn-ExtraBold.ttf")
defer face.Close()
// Create a font from the face
font := writer.NewFont(face, 45)
defer font.Close()
// Create a new writer instance.
w, _ := writer.NewWriter(font, "Hello World!", writer.DefaultOptions)
defer w.Close()
// Create a new image. (doesn't matter how.)
img := image.NewNRGBA(w.Bounds())
// Write it on your image
w.Write(img, image.Point{}, image.White)
// Save the image. (doesn't matter how.)
f, _ := os.Create("basic/result.png")
png.Encode(f, img)
}
All types of contributions are highly appreciated. especially giving me feedback on its API and how I can make it better, simpler, and easier to use.