Documentation
¶
Index ¶
- func Convert(srcPath, dstPath string, quality ...int) error
- func ConvertAll(srcDir, dstDir string, toExt string, quality ...int) (int, []error)
- func ConvertHEIC(src, dst string) error
- func DetectHEICConverter() string
- func DiffFrames(prev, curr *Canvas) float64
- func Distance(h1, h2 uint64) int
- func DownloadFFmpeg(targetDir string) (string, error)
- func EnsureFFmpeg() (string, error)
- func GenerateAudioPreview(mediaPath, outPath string) error
- func GenerateImagePreview(srcPath, outPath string, width, height int) error
- func GenerateVideoPreview(videoPath, outPath string, width, height int, frameInterval ...int) error
- func LoadFonts(paths ...string)
- func Optimize(path string, maxWidth int, quality int) error
- func PHash(img image.Image) uint64
- func ParseColor(hex string) color.Color
- func ProcessVideoFrames(totalFrames int, provider func(int) (*Canvas, error), ...) error
- func RGBAToHex(c color.RGBA) string
- func RandColor() string
- func Recognize(path string) (string, error)
- func Save(c *Canvas, path string, quality ...int) error
- type Animation
- func (a *Animation) AddFrame(c *Canvas, delay int)
- func (a *Animation) SaveGIF(path string, loopCount int) error
- func (a *Animation) TextWatermark(text string, pos Position, style *DrawStyle, opacity float64, padding int, ...)
- func (a *Animation) TileTextWatermark(text string, style *DrawStyle, opacity float64, spacing int, angle float64)
- func (a *Animation) TileWatermark(mark *Canvas, opacity float64, spacing int, angle float64)
- func (a *Animation) Watermark(mark *Canvas, pos Position, opacity float64, padding int, angle ...float64)
- type Canvas
- func Capture(videoPath string, offsetSeconds ...float64) (*Canvas, error)
- func GenerateBarcode(content string, width, height int) (*Canvas, error)
- func GenerateCaptcha(opt *CaptchaOption) *Canvas
- func GenerateQRCode(content string, size int) (*Canvas, error)
- func Load(path string) (*Canvas, error)
- func New(width, height int, backgroundColor ...string) *Canvas
- func (c *Canvas) AdjustBrightness(percent float64)
- func (c *Canvas) AdjustContrast(percent float64)
- func (c *Canvas) AdjustSaturation(percent float64)
- func (c *Canvas) Blur(sigma float64)
- func (c *Canvas) Circle(x, y, r float64, opt *DrawStyle)
- func (c *Canvas) Clear(x, y, w, h int)
- func (c *Canvas) Clone() *Canvas
- func (c *Canvas) Convolve3x3(kernel [9]float64)
- func (c *Canvas) DecodeAll() (string, error)
- func (c *Canvas) DecodeBarcode() (string, error)
- func (c *Canvas) DecodeQRCode() (string, error)
- func (c *Canvas) DrawText(x, y float64, text string, opt *TextOption)
- func (c *Canvas) ExtractPalette(n int) []ColorCount
- func (c *Canvas) Fill(w, h int)
- func (c *Canvas) FindTemplate(template *Canvas) MatchResult
- func (c *Canvas) Fit(w, h int)
- func (c *Canvas) FlipH()
- func (c *Canvas) FlipV()
- func (c *Canvas) GenerateJigsaw(x, y, size int) *JigsawResult
- func (c *Canvas) GetAverageColor() color.Color
- func (c *Canvas) Grayscale()
- func (c *Canvas) Height() int
- func (c *Canvas) Image() image.Image
- func (c *Canvas) Invert()
- func (c *Canvas) Line(x1, y1, x2, y2 float64, opt *DrawStyle)
- func (c *Canvas) Path(path string, opt *DrawStyle)
- func (c *Canvas) Pixelate(size int)
- func (c *Canvas) Put(src *Canvas, x, y int)
- func (c *Canvas) PutQRCode(content string, x, y, size int) error
- func (c *Canvas) RandBG(level int)
- func (c *Canvas) RandText(text string) [][4]float64
- func (c *Canvas) Recognize() (string, error)
- func (c *Canvas) Rect(x, y, w, h float64, opt *DrawStyle)
- func (c *Canvas) Resize(w, h int)
- func (c *Canvas) Rotate(angle float64)
- func (c *Canvas) RoundedRect(x, y, w, h, r float64, opt *DrawStyle)
- func (c *Canvas) Sepia()
- func (c *Canvas) SetColor(hex string)
- func (c *Canvas) SetFont(size float64, names ...string) error
- func (c *Canvas) Sharpen(sigma float64)
- func (c *Canvas) Sub(x, y, w, h int) *Canvas
- func (c *Canvas) TextWatermark(text string, pos Position, style *DrawStyle, opacity float64, padding int, ...)
- func (c *Canvas) TileTextWatermark(text string, style *DrawStyle, opacity float64, spacing int, angle float64)
- func (c *Canvas) TileWatermark(mark *Canvas, opacity float64, spacing int, angle float64)
- func (c *Canvas) Vignette(intensity float64)
- func (c *Canvas) WarpPerspective(srcPoints [4]image.Point, dstWidth, dstHeight int)
- func (c *Canvas) Watermark(mark *Canvas, pos Position, opacity float64, padding int, angle ...float64)
- func (c *Canvas) Width() int
- type CaptchaOption
- type ColorCount
- type CompositeFace
- func (c *CompositeFace) Close() error
- func (c *CompositeFace) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ...)
- func (c *CompositeFace) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool)
- func (c *CompositeFace) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool)
- func (c *CompositeFace) Kern(r0, r1 rune) fixed.Int26_6
- func (c *CompositeFace) Metrics() font.Metrics
- type DrawStyle
- type Format
- type JigsawResult
- type MatchResult
- type Position
- type StreamProcessor
- type TextOption
- type Video
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertAll ¶
ConvertAll 将目录下的所有符合条件的图片转换为目标格式
func ConvertHEIC ¶ added in v1.0.9
ConvertHEIC 使用探测到的工具将 HEIC 转换为 PNG 临时文件
func DetectHEICConverter ¶ added in v1.0.9
func DetectHEICConverter() string
DetectHEICConverter 探测系统中可用的 HEIC 转换工具。 优先级: sips (macOS) > heif-convert (libheif) > magick (ImageMagick)
func DownloadFFmpeg ¶
DownloadFFmpeg 下载对应系统的 FFmpeg 二进制文件
func GenerateAudioPreview ¶ added in v1.0.6
GenerateAudioPreview 提取音频用于预览或语音转写 支持根据 outPath 后缀输出格式: - .ogg: 使用 libopus (16kHz, 单声道, 12kbps), 极致压缩且保留人声特征,适合转写 - .wav: 标准 PCM (16kHz, 单声道), 无损但体积较大,部分转写引擎强制要求 - 其他: 默认使用 libopus 转为 ogg
func GenerateImagePreview ¶ added in v1.0.6
GenerateImagePreview 生成图片预览 支持缩放并裁剪以填充指定尺寸 (Fill 模式) 根据 outPath 后缀自动转换格式 (.webp, .jpg, .png 等)
func GenerateVideoPreview ¶ added in v1.0.6
GenerateVideoPreview 生成视频预览 根据 outPath 后缀判断输出格式: - .webp | .gif: 生成动态动画 (默认每 30 秒采样一帧,可通过 frameInterval 调整) - .jpg | .jpeg | .png: 生成单张预览图 (取视频中间帧) - 其他: 将 outPath 视为文件夹,在其中生成多张静态 .webp 图像 frameInterval: 每隔多少秒采样一帧,默认 30。
func ParseColor ¶
ParseColor 将多种格式的十六进制颜色字符串转换为 color.Color 支持格式: #RRGGBB, #RRGGBBAA, #RGB, #RGBA
func ProcessVideoFrames ¶
func ProcessVideoFrames(totalFrames int, provider func(int) (*Canvas, error), processor StreamProcessor) error
ProcessVideoFrames 模拟视频帧处理 (通过一系列图片或自定义逻辑) 这是一个为未来视频流处理预留的语义化接口
Types ¶
type Animation ¶
Animation 代表一个动画序列 (如 GIF)
func GenerateGIFCaptcha ¶ added in v1.0.4
func GenerateGIFCaptcha(opt *CaptchaOption) *Animation
GenerateGIFCaptcha 生成动态 GIF 验证码
func (*Animation) TextWatermark ¶ added in v1.0.5
func (a *Animation) TextWatermark(text string, pos Position, style *DrawStyle, opacity float64, padding int, angle ...float64)
TextWatermark 给动画所有帧添加文字水印
func (*Animation) TileTextWatermark ¶ added in v1.0.5
func (a *Animation) TileTextWatermark(text string, style *DrawStyle, opacity float64, spacing int, angle float64)
TileTextWatermark 给动画所有帧平铺文字水印
func (*Animation) TileWatermark ¶ added in v1.0.5
TileWatermark 给动画所有帧平铺图片水印
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas 代表一个绘图画布,封装了图像处理与绘制能力
func GenerateBarcode ¶
GenerateBarcode 生成一个条形码画布 (Code128)
func GenerateQRCode ¶
GenerateQRCode 生成一个包含二维码的画布
func (*Canvas) AdjustBrightness ¶
AdjustBrightness 调整亮度
func (*Canvas) AdjustContrast ¶
AdjustContrast 调整对比度
func (*Canvas) AdjustSaturation ¶
AdjustSaturation 调整饱和度
func (*Canvas) DecodeBarcode ¶
DecodeBarcode 识别图片中的条形码
func (*Canvas) DecodeQRCode ¶
DecodeQRCode 识别图片中的二维码
func (*Canvas) DrawText ¶
func (c *Canvas) DrawText(x, y float64, text string, opt *TextOption)
DrawText 在画布上绘制文本
func (*Canvas) ExtractPalette ¶
func (c *Canvas) ExtractPalette(n int) []ColorCount
ExtractPalette 从图像中提取调色板(主要颜色) n: 提取的前 n 种颜色
func (*Canvas) FindTemplate ¶
func (c *Canvas) FindTemplate(template *Canvas) MatchResult
FindTemplate 在当前画布中查找子图 (模板匹配) 使用简单的平方差和 (Sum of Squared Differences) 算法
func (*Canvas) GenerateJigsaw ¶ added in v1.0.4
func (c *Canvas) GenerateJigsaw(x, y, size int) *JigsawResult
GenerateJigsaw 生成滑块拼图物料
func (*Canvas) GetAverageColor ¶
GetAverageColor 计算画布的平均颜色
func (*Canvas) RoundedRect ¶
RoundedRect 绘制圆角矩形
func (*Canvas) TextWatermark ¶ added in v1.0.4
func (c *Canvas) TextWatermark(text string, pos Position, style *DrawStyle, opacity float64, padding int, angle ...float64)
TextWatermark 给画布添加文字水印
func (*Canvas) TileTextWatermark ¶ added in v1.0.5
func (c *Canvas) TileTextWatermark(text string, style *DrawStyle, opacity float64, spacing int, angle float64)
TileTextWatermark 平铺文字水印
func (*Canvas) TileWatermark ¶ added in v1.0.5
TileWatermark 平铺图片水印 spacing: 间距 angle: 旋转角度 (弧度)
func (*Canvas) WarpPerspective ¶
WarpPerspective 执行透视变换(4点变换) srcPoints: 源图像中的 4 个点 [TL, TR, BR, BL] dstWidth, dstHeight: 目标图像的尺寸
type CaptchaOption ¶
CaptchaOption 定义验证码生成选项
type ColorCount ¶
ColorCount 记录颜色及其出现的频率
type CompositeFace ¶
CompositeFace 支持多字体回退的字体接口实现
func (*CompositeFace) Close ¶
func (c *CompositeFace) Close() error
func (*CompositeFace) GlyphAdvance ¶
func (c *CompositeFace) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool)
func (*CompositeFace) GlyphBounds ¶
func (c *CompositeFace) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool)
func (*CompositeFace) Metrics ¶
func (c *CompositeFace) Metrics() font.Metrics
type DrawStyle ¶
type DrawStyle struct {
StrokeColor string
StrokeWidth float64
LineCap gg.LineCap
LineJoin gg.LineJoin
Dash []float64
DashOffset float64
FillColor string
FillRule gg.FillRule
ShadowColor string
ShadowOffset float64
ShadowBlur float64
}
DrawStyle 定义图形绘制样式
type JigsawResult ¶ added in v1.0.4
JigsawResult 滑块拼图结果
type MatchResult ¶
MatchResult 模板匹配结果
type StreamProcessor ¶
StreamProcessor 定义帧处理器函数
type TextOption ¶
type TextOption struct {
Width float64
Height float64
LineHeight float64
Align string // left, center, right
VAlign string // top, middle, bottom
Color string
BgColor string
BorderColor string
BorderWidth float64
Padding [4]float64 // top, right, bottom, left
}
TextOption 定义文本绘制选项
type Video ¶
type Video struct {
FFmpegPath string
}
Video 代表一个视频操作封装
func (*Video) CreateVideoFromImages ¶
CreateVideoFromImages 从一系列图片创建视频
func (*Video) ExtractFrame ¶
ExtractFrame 从视频中提取指定时间的帧
func (*Video) WatermarkVideo ¶ added in v1.0.4
WatermarkVideo 给视频添加水印 videoPath: 输入视频 markPath: 水印图片路径 outPath: 输出视频路径 pos: 水印位置 (使用 FFmpeg 语法, 如 '10:10', 'main_w-overlay_w-10:10')