https://github.com/bububa/tableimage
table image generator
https://github.com/bububa/tableimage
image renderer rendering-engine table
Last synced: 11 months ago
JSON representation
table image generator
- Host: GitHub
- URL: https://github.com/bububa/tableimage
- Owner: bububa
- License: apache-2.0
- Created: 2021-08-24T12:37:36.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-07T03:11:05.000Z (over 3 years ago)
- Last Synced: 2025-04-15T03:46:09.238Z (about 1 year ago)
- Topics: image, renderer, rendering-engine, table
- Language: Go
- Homepage:
- Size: 9.46 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tableimage generator
Generates a table inside of a image based on the provided data
[](https://pkg.go.dev/github.com/bububa/tableimage)
[](https://github.com/bububa/tableimage/actions/workflows/go.yml)
[](https://github.com/bububa/tableimage/actions/workflows/goreleaser.yml)
[](https://github.com/bububa/tableimage)
[](https://goreportcard.com/report/github.com/bububa/tableimage)
[](https://github.com/bububa/tableimage/blob/master/LICENSE)
[](https://GitHub.com/bububa/tableimage/releases/)
### Features
- support border, font, color, padding, margin etc. style settings
- style inherit, could set style in cell, row, table level
- support image in table
- support text dpi setting, font size setting based on 72dpi
- support inline text style (inline text format styled text.)
### Example:

### Usage
```go
package main
import (
"image"
"log"
"os"
"github.com/bububa/tableimage"
"github.com/llgcode/draw2d"
)
func main() {
imageURL := "https://images.pexels.com/photos/906052/pexels-photo-906052.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=200"
ti, err := tableimage.New(
tableimage.WithBgColor("#FFFFFF"),
tableimage.WithBorderColor("#0277BD"),
tableimage.WithFontSize(11),
tableimage.WithDPI(144),
tableimage.WithFontData(&draw2d.FontData{
Name: "NotoSansCJKsc",
Family: draw2d.FontFamilySans,
Style: draw2d.FontStyleNormal,
}),
tableimage.WithFontFolder("./font"),
)
if err != nil {
log.Fatalln(err)
return
}
headerFont := &tableimage.Font{
Size: 13,
Data: &draw2d.FontData{
Name: "Roboto",
Family: draw2d.FontFamilySans,
Style: draw2d.FontStyleBold,
},
}
footerFont := &tableimage.Font{
Size: 10,
Data: &draw2d.FontData{
Name: "NotoSansCJKsc",
Family: draw2d.FontFamilySans,
Style: draw2d.FontStyleNormal,
},
}
headerStyle := &tableimage.Style{
Font: headerFont,
}
caption := &tableimage.Cell{
Text: "this is a caption very long long long ago adsfasdfwe;alsdkfasdfasf asdfajsdf",
Style: &tableimage.Style{
Color: "#3F51B5",
Font: headerFont,
},
}
tfooter := &tableimage.Cell{
Text: "this is a tabel footer very long long long ago adsfasdfwe;alsdkfasdfasf asdfajsdf",
Style: &tableimage.Style{
Color: "#D7CCC8",
Font: footerFont,
},
}
rows := []tableimage.Row{
{
Style: headerStyle,
Cells: []tableimage.Cell{
{
Text: "Id",
},
{
Text: "Name",
},
{
Style: &tableimage.Style{
Color: "#008000",
},
Text: "Price",
},
},
},
{
Cells: []tableimage.Cell{
{
Text: "2223",
},
{
Style: &tableimage.Style{
Color: "#000",
MaxWidth: 100,
Align: tableimage.CENTER,
},
Text: "这是一个真正的table图片",
},
{
Style: &tableimage.Style{
Color: "#0000ff",
},
Text: "2000$",
},
},
},
{
Cells: []tableimage.Cell{
{
Style: &tableimage.Style{
Color: "#6A1B9A",
VAlign: tableimage.TOP,
},
Text: "11",
},
{
Style: &tableimage.Style{
Color: "#FFF",
MaxWidth: 100,
BgColor: "#D32F2F",
},
IgnoreInlineStyle: false,
Text: "A more cooler product this time on 3 lines",
},
{
Style: &tableimage.Style{
Color: "#0000ff",
Align: tableimage.RIGHT,
VAlign: tableimage.BOTTOM,
},
Text: "200$",
},
},
},
{
Cells: []tableimage.Cell{
{
Text: "2223",
Image: &tableimage.Image{
URL: imageURL,
Size: image.Pt(80, 0),
VAlign: tableimage.BOTTOM,
Padding: tableimage.NewPaddingY(4),
},
Style: &tableimage.Style{
Align: tableimage.RIGHT,
},
},
{
Style: &tableimage.Style{
Color: "#000",
MaxWidth: 100,
Align: tableimage.CENTER,
},
Image: &tableimage.Image{
URL: imageURL,
Size: image.Pt(80, 0),
VAlign: tableimage.TOP,
Padding: tableimage.NewPaddingY(4),
},
Text: "这是一个真正的table图片",
},
{
Style: &tableimage.Style{
Color: "#0000ff",
},
Text: "2000$",
},
},
},
{
Cells: []tableimage.Cell{
{
Text: "2223",
Image: &tableimage.Image{
URL: imageURL,
Size: image.Pt(80, 0),
Align: tableimage.LEFT,
Padding: tableimage.NewPaddingX(4),
},
Style: &tableimage.Style{
VAlign: tableimage.BOTTOM,
},
},
{
Style: &tableimage.Style{
Color: "#000",
MaxWidth: 150,
Align: tableimage.RIGHT,
VAlign: tableimage.MIDDLE,
},
Image: &tableimage.Image{
URL: imageURL,
Size: image.Pt(80, 0),
Align: tableimage.RIGHT,
Padding: tableimage.NewPaddingX(4),
},
Text: "这是一个真正的table图片",
},
{
Style: &tableimage.Style{
Color: "#0000ff",
},
Text: "2000$",
},
},
},
}
img, err := ti.Draw(rows, caption, tfooter)
if err != nil {
log.Fatalln(err)
return
}
f, err := os.Create("./test.png")
if err != nil {
log.Fatalln(err)
return
}
defer f.Close()
tableimage.Write(f, img, tableimage.PNG)
}
```