gif

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package gif provides GIF decoding, encoding, and frame-level editing operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCropDimensions    = errors.New("crop dimensions must be positive")
	ErrCropOutOfBounds   = errors.New("crop out of bounds")
	ErrDecodeGIF         = errors.New("failed to decode GIF")
	ErrEncodeGIF         = errors.New("failed to encode GIF")
	ErrNoFrames          = errors.New("GIF has no frames")
	ErrInvalidDimensions = errors.New("GIF has invalid dimensions")
	ErrResizeDimensions  = errors.New("invalid resize dimensions")
	ErrSpeedFactor       = errors.New("speed factor must be positive")
	ErrLoadFont          = errors.New("failed to load font")
	ErrInvalidFrameRange = errors.New("invalid frame range")
	ErrNoVideoFrames     = errors.New("no frames extracted from video")
	ErrInvalidFPS        = errors.New("frame rate must be between 1 and 60")
)

Sentinel errors returned by gif processing functions.

Functions

func AddText

func AddText(gif *gifstd.GIF, opts TextOptions) (*gifstd.GIF, error)

AddText overlays text on every frame of the GIF and returns a new GIF.

func Crop

func Crop(gif *gifstd.GIF, cropOptions CropOptions) (*gifstd.GIF, error)

Crop returns a new GIFFile where every frame is only selected portion.

func DecodeBytes

func DecodeBytes(data []byte) (*gifstd.GIF, error)

DecodeBytes decodes a GIF from a byte slice.

func DeepFry

func DeepFry(gif *gifstd.GIF) (*gifstd.GIF, error)

DeepFry applies an extreme saturation + contrast boost, warm tint, noise, and heavy sharpening to produce the classic "deep fried" meme look.

func EncodeBytes

func EncodeBytes(gif *gifstd.GIF) ([]byte, error)

EncodeBytes encodes a GIF to a byte slice.

func FlipH added in v1.2.0

func FlipH(g *gifstd.GIF) (*gifstd.GIF, error)

FlipH returns a new GIF with every frame flipped horizontally.

func FlipV added in v1.2.0

func FlipV(g *gifstd.GIF) (*gifstd.GIF, error)

FlipV returns a new GIF with every frame flipped vertically.

func FramesToGIF added in v1.1.0

func FramesToGIF(frames [][]byte, width, height, fps int, highQuality bool) (*gifstd.GIF, error)

FramesToGIF converts a sequence of raw RGBA frames into a GIF. Each frame must be width*height*4 bytes in RGBA order. fps must be between 1 and 60; the GIF frame delay is derived from it. If highQuality is true, each frame's palette is built using median cut quantization instead of the fixed Plan9 palette.

func Grayscale

func Grayscale(gif *gifstd.GIF) (*gifstd.GIF, error)

Grayscale converts every image to grayscale using luminance weights.

func ParseColor

func ParseColor(str string) color.Color

ParseColor converts a color name or hex string to a color.Color.

func Resize

func Resize(gif *gifstd.GIF, width, height int) (*gifstd.GIF, error)

Resize scales every frame of the GIF to the given dimensions. Pass width=0 to auto-calculate from height, or height=0 to auto-calculate from width.

func Reverse added in v1.2.0

func Reverse(g *gifstd.GIF) (*gifstd.GIF, error)

Reverse returns a new GIF with frames in reverse order.

func Rotate90CCW added in v1.2.0

func Rotate90CCW(g *gifstd.GIF) (*gifstd.GIF, error)

Rotate90CCW returns a new GIF with every frame rotated 90° counter-clockwise.

func Rotate90CW added in v1.2.0

func Rotate90CW(g *gifstd.GIF) (*gifstd.GIF, error)

Rotate90CW returns a new GIF with every frame rotated 90° clockwise.

func Rotate180 added in v1.2.0

func Rotate180(g *gifstd.GIF) (*gifstd.GIF, error)

Rotate180 returns a new GIF with every frame rotated 180°.

func Speed

func Speed(gif *gifstd.GIF, factor float64) (*gifstd.GIF, error)

Speed returns a new GIF with frame delays divided by factor. factor > 1 = faster, factor < 1 = slower. Minimum delay is 2 (2/100s).

func Trim

func Trim(gif *gifstd.GIF, start, end int) (*gifstd.GIF, error)

Trim returns a new GIF containing only frames [start, end] (inclusive, 0-based).

Types

type CropOptions

type CropOptions struct {
	X, Y, Width, Height int
}

CropOptions defines the region to crop, in pixels relative to the top-left of the GIF.

type TextOptions

type TextOptions struct {
	Text  string
	Size  float64
	Color color.Color
	X     int // left edge in GIF pixels
	Y     int // top edge in GIF pixels
	Font  string
}

TextOptions configures text overlay rendering

Jump to

Keyboard shortcuts

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