Documentation
¶
Index ¶
- Variables
- type PadMode
- type ProcessOptions
- type Processor
- func (p *Processor) Process(ctx context.Context, r io.Reader, mime string) ([]byte, error)
- func (p *Processor) ProcessAnimation(ctx context.Context, r io.Reader) ([]byte, error)
- func (p *Processor) ProcessImage(ctx context.Context, r io.Reader) ([]byte, error)
- func (p *Processor) Validate(data []byte) (*ValidationResult, error)
- type ProcessorOption
- func WithBgColor(c *color.RGBA) ProcessorOption
- func WithEXIF(meta *exif.Meta) ProcessorOption
- func WithFPS(fps int) ProcessorOption
- func WithLossless(l bool) ProcessorOption
- func WithMaxConcurrency(max int) ProcessorOption
- func WithMaxDuration(d time.Duration) ProcessorOption
- func WithMaxFileSizeKB(kb int) ProcessorOption
- func WithPadMode(m PadMode) ProcessorOption
- func WithQuality(q int) ProcessorOption
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
var ( ErrFFmpegNotFound = errors.New("sticker: ffmpeg binary not found in PATH") ErrTooLarge = errors.New("sticker: output exceeds max file size after re-encoding") ErrInvalidFormat = errors.New("sticker: unsupported or undetectable input format") ErrInvalidDimension = errors.New("sticker: cannot produce 512x512 from input") ErrContextCanceled = errors.New("sticker: processing canceled via context") )
Functions ¶
This section is empty.
Types ¶
type PadMode ¶
type PadMode int
PadMode dictates how an image should be fitted into a 512x512 canvas.
type ProcessOptions ¶
type ProcessOptions struct {
Quality int // WebP quality 1–100 (default: 80)
Lossless bool // Use lossless WebP (increases size)
MaxFileSizeKB int // Enforce max KB (default: 100 for static, 500 for animated)
FPS int // Target FPS for animated (default: 15)
MaxDuration time.Duration // Max animated duration (default: 3s)
BgColor *color.RGBA // Optional background fill (nil = transparent)
PadMode PadMode // How to fit into 512x512
EXIF *exif.Meta // If non-nil, EXIF metadata is injected after encoding
}
ProcessOptions controls encoding behavior
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor is the main entry point to parse, process, and validate stickers.
func (*Processor) Process ¶
Process auto-detects if the input is animated or not. If mime indicates video/gif, it calls ProcessAnimation. Otherwise ProcessImage.
func (*Processor) ProcessAnimation ¶
ProcessAnimation converts an animated image/video into a WhatsApp-compliant animated WebP sticker.
func (*Processor) ProcessImage ¶
ProcessImage converts a static image into a WhatsApp-compliant WebP sticker.
type ProcessorOption ¶
type ProcessorOption func(*Processor)
ProcessorOption is a functional option for configuring a Processor
func WithBgColor ¶
func WithBgColor(c *color.RGBA) ProcessorOption
WithBgColor sets an optional background fill color. Default: nil (transparent).
func WithEXIF ¶
func WithEXIF(meta *exif.Meta) ProcessorOption
WithEXIF injects WhatsApp sticker EXIF metadata after encoding. If nil, no EXIF chunk is written. Default: nil.
func WithFPS ¶
func WithFPS(fps int) ProcessorOption
WithFPS sets the target frame rate for animated stickers. Default: 15.
func WithLossless ¶
func WithLossless(l bool) ProcessorOption
WithLossless enables lossless WebP encoding. Default: false.
func WithMaxConcurrency ¶
func WithMaxConcurrency(max int) ProcessorOption
WithMaxConcurrency sets the maximum number of concurrent ffmpeg executions
func WithMaxDuration ¶
func WithMaxDuration(d time.Duration) ProcessorOption
WithMaxDuration sets the maximum duration for animated stickers. Default: 3s.
func WithMaxFileSizeKB ¶
func WithMaxFileSizeKB(kb int) ProcessorOption
WithMaxFileSizeKB sets the maximum output file size in kilobytes. Default: 100 for static, 500 for animated (auto-set by Process).
func WithPadMode ¶
func WithPadMode(m PadMode) ProcessorOption
WithPadMode sets how the image is fitted into the 512×512 canvas. Default: PadFit.
func WithQuality ¶
func WithQuality(q int) ProcessorOption
WithQuality sets the WebP encoding quality (1–100). Default: 80.