imgHelper

package
v1.5.21 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Buff2Image

func Buff2Image(bytes []byte, filePath string) (err error)

Buff2Image 字节转图片

func CropCircleCenter

func CropCircleCenter(target image.Image) image.Image

CropCircleCenter 将图片从中心裁切成最大圆

func CropCornerRadius

func CropCornerRadius(target *gg.Context, radius float64) *gg.Context

CropCornerRadius 裁圆角

func DownloadNetworkFileToDir

func DownloadNetworkFileToDir(bgImgURL string, localDirPath string) (bgImgFilePath string, err error)

DownloadNetworkFileToDir 根据网络图片地址,转化为本地文件及路径 localDirPath 例子 /tmp/

func DownloadNetworkImg

func DownloadNetworkImg(bgImgURL string) (bgImgFilePath string, err error)

DownloadNetworkImg 根据网络图片地址,转化为本地文件及路径

func DrawFontToImage

func DrawFontToImage(rgba *image.RGBA, pt image.Point, content string, fontStyle FontStyle) (err error)

DrawFontToImage 图片插入文字

func GetFontType

func GetFontType(fontFilePath string) (fontType *truetype.Font, err error)

GetFontType 根据文件地址构建字库

func Image2RGBA

func Image2RGBA(img image.Image) *image.RGBA

Image2RGBA 图片转换成image.RGBA

func LocalImg2Buff

func LocalImg2Buff(filePath string) (sendS3 []byte, err error)

LocalImg2Buff 本地图片转字节

func MergeLocalImg

func MergeLocalImg(bgImgFilePath string, newFilePath string, coverImgSlice ...CoverImgInterface) (err error)

MergeLocalImg 拼合本地图片

func MergeNetworkImg

func MergeNetworkImg(bgImgURL string, newFilePath string, coverImgSlice []*NetworkCoverImg) (err error)

MergeNetworkImg 拼合网络图片 这个函数会将图片先下载到项目根目录下的/temp,记得给权限

func OpenImageFile

func OpenImageFile(localUri string) (image.Image, error)

func OpenImageFileContext

func OpenImageFileContext(localUri string) (*gg.Context, error)

OpenImageFileContext 获取

func SaveImage

func SaveImage(targetPath string, m image.Image) error

Types

type CoverImgInterface

type CoverImgInterface interface {
	GetLocalFilePath() string
	GetSize() *Size
	GetPosition() *Position
	GetRoundCorner() int
	GetCropCircle() bool
}

type FontStyle

type FontStyle struct {
	DPI         float64
	Family      *truetype.Font
	Color       color.RGBA
	Width       int
	Size        float64
	SpaceAmount int          // 前面空几格
	Align       HorizonAlign // 水平对齐方式
}

type HorizonAlign

type HorizonAlign int8
const Center HorizonAlign = 2
const Left HorizonAlign = 1
const Right HorizonAlign = 3

type LocalCoverImg

type LocalCoverImg struct {
	LocalFilePath string // 本地文件地址
	Size          *Size
	Position      *Position
	RoundCorner   int
	CropCircle    bool
}

func (*LocalCoverImg) GetCropCircle

func (t *LocalCoverImg) GetCropCircle() bool

func (*LocalCoverImg) GetLocalFilePath

func (t *LocalCoverImg) GetLocalFilePath() string

func (*LocalCoverImg) GetPosition

func (t *LocalCoverImg) GetPosition() *Position

func (*LocalCoverImg) GetRoundCorner

func (t *LocalCoverImg) GetRoundCorner() int

func (*LocalCoverImg) GetSize

func (t *LocalCoverImg) GetSize() *Size

type NetworkCoverImg

type NetworkCoverImg struct {
	NetworkURL    string // 网络文件地址
	LocalFilePath string // 本地文件地址
	Size          *Size
	Position      *Position
	RoundCorner   int
	CropCircle    bool
}

func (*NetworkCoverImg) GetCropCircle

func (t *NetworkCoverImg) GetCropCircle() bool

func (*NetworkCoverImg) GetLocalFilePath

func (t *NetworkCoverImg) GetLocalFilePath() string

func (*NetworkCoverImg) GetPosition

func (t *NetworkCoverImg) GetPosition() *Position

func (*NetworkCoverImg) GetRoundCorner

func (t *NetworkCoverImg) GetRoundCorner() int

func (*NetworkCoverImg) GetSize

func (t *NetworkCoverImg) GetSize() *Size

type Position

type Position struct {
	X float64
	Y float64
}

func GetPositionFromStr

func GetPositionFromStr(str string) (imgNo int, position *Position)

GetPositionFromStr 从字符串中转换成point 0,120,234 这种格式

type Size

type Size struct {
	Width  float64
	Height float64
}

func GetSizeFromStr

func GetSizeFromStr(str string) (size *Size)

GetSizeFromStr 从字符串中转换成size 200,400 这种格式

Jump to

Keyboard shortcuts

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