GithubHelp home page GithubHelp logo

ggishant / go-table-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from techbinator/go-table-image

0.0 0.0 0.0 1.57 MB

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

License: MIT License

Go 100.00%

go-table-image's Introduction

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

go-table-image's People

Contributors

techbinator avatar ggishant avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.