Site icon Golang Libraries, Apps, Golang Jobs and Go Tutorials

How to Generate text to image in Golang

how to generate text to image in golang

The reasons why I created this application is for me to share text content like Linux configuration and source code snippet in WhatsApp or other messaging application. Another is to generate featured image for social media posts in Twitter, Facebook or LinkedIn.

Project Structure

Source code

The complete source code is available on github:

The file main.go contains the initialization and configuration codes to run this application.

package main

import (

	rice ""

var (
	configuration models.Config

func main() {
	pid := os.Getpid()
	err := ioutil.WriteFile("", []byte(strconv.Itoa(pid)), 0666)
	if err != nil {

	var configLocation string
	flag.StringVar(&configLocation, "config", "config.yml", "Set the location of configuration file")

	sprocket.LoadYAML(configLocation, &configuration)

	viewBox := rice.MustFindBox("views")
	staticBox := rice.MustFindBox("static")
	controllersHub := controllers.New(viewBox, nil, nil, &configuration)
	staticFileServer := http.StripPrefix("/static/", http.FileServer(staticBox.HTTPBox()))

	router := bone.New()
	router.Get("/static/", staticFileServer)

	port := strconv.Itoa(configuration.HTTP.Port)
	if os.Getenv("ASPNETCORE_PORT") != "" { // get enviroment variable that set by ACNM
		port = os.Getenv("ASPNETCORE_PORT")

	httpServer := &http.Server{
		Addr:         ":" + port,
		Handler:      router,
		ReadTimeout:  120 * time.Second,
		WriteTimeout: 120 * time.Second,

	if configuration.HTTP.IsTLS {
		log.Printf("Server running at https://localhost/tools:%s/\n", port)
		log.Fatal(httpServer.ListenAndServeTLS(configuration.HTTP.ServerCert, configuration.HTTP.ServerKey))
	log.Printf("Server running at http://localhost/tools:%s/\n", port)
The page_controller.go handles both the page rendering and image generation.
Exit mobile version