tableimage

package module
v0.0.0-...-356ea81 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2022 License: MIT Imports: 11 Imported by: 0

README

go lang table image

Generates a table inside of a image (png or jpg format) based on the provided data

GoDoc

Goals
  • Provide a simple interface in order to generate tables as image programatically
  • Save as png or jpg
  • Ability to modify colors, multi line columns, image size optimisation
  • Do not use any other 3rd party libraries, in order to provide a small bundle size
Usage examples
  • Send slack notification for bigger reports that the Slack api will send as a huge attachment
  • Use in combination with a package like https://github.com/rivo/tview in order to create tables from terminal
  • Add implementation that would fetch data for example from a json file and generate the image from that
Usage
package main

import (
	"tableimage"
)

func main() {
	ti := tableimage.Init("#fff", tableimage.PNG, "./test.png")

	ti.AddTH(
		tableimage.TR{
			BorderColor: "#000",
			Tds: []tableimage.TD{
				tableimage.TD{
					Color: "#000",
					Text:  "Id",
				},
				tableimage.TD{
					Color: "#000",
					Text:  "Name",
				},
				tableimage.TD{
					Color: "#008000",
					Text:  "Price",
				},
			},
		},
	)

	ti.AddTRs(
		[]tableimage.TR{
			tableimage.TR{
				BorderColor: "#000",
				Tds: []tableimage.TD{
					tableimage.TD{
						Color: "#000",
						Text:  "2223",
					},
					tableimage.TD{
						Color: "#000",
						Text:  "Really cool product on two lines",
					},
					tableimage.TD{
						Color: "#0000ff",
						Text:  "2000$",
					},
				},
			},
			tableimage.TR{
				BorderColor: "#000",
				Tds: []tableimage.TD{
					tableimage.TD{
						Color: "#000",
						Text:  "11",
					},
					tableimage.TD{
						Color: "#000",
						Text:  "A more cooler product this time on 3 lines",
					},
					tableimage.TD{
						Color: "#0000ff",
						Text:  "200$",
					},
				},
			},
			tableimage.TR{
				BorderColor: "#000",
				Tds: []tableimage.TD{
					tableimage.TD{
						Color: "#000",
						Text:  "2231",
					},
					tableimage.TD{
						Color: "#000",
						Text:  "Lenovo",
					},
					tableimage.TD{
						Color: "#000",
						Text:  "20400$",
					},
				},
			},
		},
	)
	ti.Save()
}

Outputs:

Example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(backgroundColor string, fileType FileType, filePath string) tableImage

Init initialise the table image receiver

Types

type FileType

type FileType string

FileType the image format png or jpg

const (
	PNG  FileType = "png"
	JPEG FileType = "jpg"
)

type TD

type TD struct {
	Text  string
	Color string
}

TD a table data container

type TR

type TR struct {
	BorderColor string
	Tds         []TD
}

TR the table row

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL