gimage

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 14 Imported by: 0

README

gimage

grid image, text image ...

Example Text Image

textImage := gridimage.NewTextImage(4)
textImage.Title = "请写出以下文字:"
textImage.Text = "我们每个人都是中国人热爱劳动"
textImage.FontPath = "/Library/Fonts/华文仿宋.ttf"
textImage.HeaderHeight = 0
textImage.CellWidth = 30
textImage.CellHeight = 20
textImage.Gap = 5
textImage.Padding = 5

index := fmt.Sprintf("%d", glib.RandInt(999)%4)
textImage.Backgroud = "./assets/img/verify/000/" + index + ".png"

dataBytes, err := textImage.GetImage()
if err != nil {
    jsonResult.SetError(err)
    return result.JsonResult(ctx, jsonResult)
}

//保存验证码
text := textImage.GetData()
log.Printf("GetTextImage text: %s", text)
ctrl.SaveSessionValue(ctx, settings.Settings.ValidateCode.Image, text)

ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
ctx.Header("Pragma", "no-cache")
ctx.Header("Expires", "0")

return result.DataResult(ctx, dataBytes)

Example Grid Image

gridImage := gridimage.NewGridImage(datas)
gridImage.HeaderHeight = 30
gridImage.CellWidth = 50
gridImage.CellHeight = 50
gridImage.Gap = 5
gridImage.Padding = 50

index := fmt.Sprintf("%d", glib.RandInt(999)%4)
gridImage.Backgroud = "./assets/img/verify/000/" + index + ".png"

dataBytes, err := gridImage.GetImage()
if err != nil {
    jsonResult.SetError(err)
    return result.JsonResult(ctx, jsonResult)
}

ctx.Header("Cache-Control", "no-cache, no-store, must-revalidate")
ctx.Header("Pragma", "no-cache")
ctx.Header("Expires", "0")

return result.DataResult(ctx, dataBytes)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGridImage

func NewGridImage(count int, datas []*GridItem) *gridImage

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 获取网格图实例 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Types

type GridItem

type GridItem struct {
	Title          string
	Path           string
	Words          []string
	Filenames      []int
	SelectedIndexs []int
}

================================================================================ * 网格图片 * qq group: 582452342 * email : 2091938785@qq.com * author : 美丽的地球啊 - mliu * ================================================================================

type IImage

type IImage interface {
	GetText() []string
	GetImage() ([]byte, error)
	SetOption(ImageOption)
}

================================================================================ * 五线谱图片 * qq group: 582452342 * email : 2091938785@qq.com * author : 美丽的地球啊 - mliu * ================================================================================

func NewLineImage

func NewLineImage(title string, texts []string, head string, count int) IImage

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 初始化五线谱图 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

func NewTextImage

func NewTextImage(title string, texts []string, count int) IImage

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 初始化文字图 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

type ImageOption

type ImageOption struct {
	HeaderHeight int
	CellWidth    int
	CellHeight   int
	Gap          int
	Padding      int
	Backgroud    string
	FontPath     string
	FontSize     float64
}

================================================================================ * 五线谱图片 * qq group: 582452342 * email : 2091938785@qq.com * author : 美丽的地球啊 - mliu * ================================================================================

Jump to

Keyboard shortcuts

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