gif

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package gif renders asciinema cast files to animated GIFs.

Index

Constants

View Source
const (
	// DefaultAggVersion is the agg release version downloaded when auto-fetching.
	// The fork (see aggReleaseRepo) ships sixel and Kitty graphics rendering;
	// pinned here until that support lands in an upstream asciinema/agg release.
	DefaultAggVersion = "v1.11.2-sixel"
)

Variables

View Source
var ErrDownload = fmt.Errorf("agg download failed")

ErrDownload indicates that automatic agg download failed.

View Source
var ErrValidation = errors.New("gif validation failed")

ErrValidation indicates that a rendered GIF failed validation.

Functions

func CacheDir

func CacheDir() string

CacheDir returns the default cache directory for auto-downloaded agg.

func CachedAggPath

func CachedAggPath() string

CachedAggPath returns the expected path of the cached agg binary.

func DownloadAgg

func DownloadAgg() (string, error)

DownloadAgg downloads the agg binary for the current platform to the cache dir. Returns the path to the downloaded binary.

func MeasureColumnWidthPx

func MeasureColumnWidthPx(ctx context.Context, config Config) (float64, error)

MeasureColumnWidthPx renders two short probe casts that differ only in column count and returns the pixel width agg actually advances per column for the given font configuration. agg lays columns out at a fixed advance plus fixed horizontal padding, so (wideWidth - narrowWidth) / (wideCols - narrowCols) yields the per-column width independent of that padding — and independent of which font agg resolves on the host, which a static formula cannot know.

func Render

func Render(ctx context.Context, castPath, outputPath string, config Config) error

Render converts an asciinema cast file to an animated GIF with agg.

Types

type Config

type Config struct {
	AggPath       string
	Theme         string
	Speed         float64
	Font          string
	FontSize      int
	LineHeight    float64
	LetterSpacing float64
	// Select is passed to agg's --select to render only part of the timeline.
	// Use it to trim a recording's lead-in (e.g. "0.2.." drops the first 0.2s),
	// which is handy for sixel apps that paint a cell-based fallback frame
	// before the terminal's sixel-capability handshake completes.
	Select string
}

Config controls agg GIF rendering.

func NormalizeConfig

func NormalizeConfig(config Config) Config

NormalizeConfig fills unset fields with the defaults Render applies, so callers (e.g. the sixel cell-size reports) can mirror the font metrics agg will render with.

type Validation

type Validation struct {
	Frames        int
	Width         int
	Height        int
	PixelVariance int
}

Validation describes a decoded GIF.

func Validate

func Validate(path string) (Validation, error)

Validate decodes a GIF and verifies it has visible animation content.

Jump to

Keyboard shortcuts

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