canvas

package
v0.0.1-alpha.15 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageResize

func ImageResize(input image.Image, width uint, height uint) image.Image

ImageResize 图片缩放

func ImageRound

func ImageRound(input image.Image) image.Image

ImageRound 图片变圆

func LoadLocalFont

func LoadLocalFont(fontPath string, fontSize float64) (font.Face, error)

LoadLocalFont 字体缓存在内存中

func LoadLocalImage

func LoadLocalImage(imagePath string) (image.Image, error)

LoadLocalImage 本地图片缓存在内存中

Types

type Canvas

type Canvas struct {
	Width  uint
	Height uint
	// contains filtered or unexported fields
}

Canvas 画布

func NewCanvas

func NewCanvas(width, height int) *Canvas

NewCanvas 创建新的画布

func NewCanvasWithImage

func NewCanvasWithImage(background image.Image) *Canvas

NewCanvasWithImage 从图片创建新的画布

func NewCanvasWithLocalImagePath

func NewCanvasWithLocalImagePath(imagePath string) (*Canvas, error)

NewCanvasWithLocalImagePath 从本地图片创建新的画布

func (*Canvas) DrawImage

func (canvas *Canvas) DrawImage(img image.Image, offsetX int, offsetY int)

DrawImage 绘制图片

func (*Canvas) DrawLine

func (canvas *Canvas) DrawLine(color color.Color, offsetX, offsetY, length float64)

DrawLine 绘制横线

func (*Canvas) DrawRect

func (canvas *Canvas) DrawRect(x, y, w, h float64, c color.Color)

DrawRect 绘制矩形

func (*Canvas) DrawText

func (canvas *Canvas) DrawText(opt *TextConfig) error

DrawText 绘制图片

func (*Canvas) MeasureString

func (canvas *Canvas) MeasureString(opt *TextConfig) float64

MeasureString 测量文字

func (*Canvas) Output

func (canvas *Canvas) Output() ([]byte, error)

Output 输出 PNG 图片

func (*Canvas) SavePNG

func (canvas *Canvas) SavePNG(path string) error

SavePNG 保存 PNG 图片

type TextConfig

type TextConfig struct {
	Text     string
	FontName string
	FontSize float64
	Color    color.Color
	OffsetX  float64
	OffsetY  float64
	AlignX   float64
	AlignY   float64
	MaxWidth float64
}

TextConfig 绘制文字配置

Jump to

Keyboard shortcuts

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