termimage

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package termimage renders images to terminals.

Backends cover the modern image protocols — kitty graphics (kitty, Ghostty, Konsole), iTerm2 inline images (iTerm2, WezTerm), and sixel (Windows Terminal, foot, mlterm, xterm) — plus ANSI tiers that work everywhere: truecolor half blocks and a plain ASCII ramp.

Everything is written in-repo on the standard library alone: no cgo, no new module dependencies, no copied protocol code. Decoding uses image/png, image/jpeg, and image/gif; base64 and PNG encoding are stdlib; scaling, adaptive palette quantization, and optional dithering are ours and deterministic, so protocol output is golden-testable.

Backend selection is automatic by default: environment signals pick kitty and iTerm2 terminals, a DA1 probe asks about sixel on real consoles, and the ANSI tiers catch everything else. An explicit Backend always wins. A disabled Scheme degrades Auto to ASCII, so piped output stays plain text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, img image.Image, opts Options, scheme style.Scheme) error

Render writes img to w in the chosen backend. Inside tmux, kitty and iTerm2 streams are wrapped for passthrough (the allow-passthrough option must be on); sixel goes raw because tmux 3.4+ renders it natively.

func String

func String(img image.Image, opts Options, scheme style.Scheme) (string, error)

String renders img and returns the escape stream or text.

Types

type Backend

type Backend int

Backend selects an image protocol or ANSI tier.

const (
	// Auto detects the best backend for the current terminal.
	Auto Backend = iota
	// Kitty is the kitty graphics protocol.
	Kitty
	// ITerm2 is the iTerm2 OSC 1337 inline image protocol.
	ITerm2
	// Sixel is DEC sixel (DCS).
	Sixel
	// HalfBlock paints two pixel rows per cell with upper half blocks.
	HalfBlock
	// ASCII paints luminance through a character ramp.
	ASCII
)

Backends from richest to plainest.

func Detect

func Detect() Backend

Detect picks the richest backend the current terminal can host: environment signals first, a sixel DA1 probe on real consoles next, ANSI half blocks last.

func (Backend) String

func (b Backend) String() string

String names the backend.

type Options

type Options struct {
	// Backend forces a protocol; zero Auto detects from the terminal.
	Backend Backend
	// Width caps the render in cells; zero uses the terminal width.
	Width int
	// Height caps the render in cells; zero keeps the image aspect.
	Height int
	// Dither enables Floyd-Steinberg error diffusion wherever a backend
	// quantizes: the sixel adaptive palette, 256-color half blocks, and
	// the ascii ramp. Exact-pixel paths (kitty, iterm2, truecolor half
	// blocks) send full color and are unaffected.
	Dither bool
	// Background flattens transparency when it has alpha: every backend
	// blends the image over this color. The zero value keeps
	// transparency instead — kitty and iterm2 send native alpha, sixel
	// leaves those pixels unpainted, and half blocks and ascii render
	// them as blanks, all letting the terminal background show through.
	Background color.RGBA
	// CellWidth and CellHeight override the per-cell pixel estimate
	// used for sizing; zero queries the terminal.
	CellWidth  int
	CellHeight int
	// ImageID is the kitty graphics image id. Zero sends every render
	// as a fresh anonymous image, so sequential renders coexist; a
	// non-zero id makes a retransmit replace earlier renders of that
	// id in place, which suits redrawing a widget or an animation.
	ImageID uint32
}

Options tunes a render.

Jump to

Keyboard shortcuts

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