termimg

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: 1 module, 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 termimg shows images in a terminal: as colored half blocks, which any terminal with 24-bit color can show and which mix with other text, or full size through the kitty, iTerm2 or sixel protocols.

Index

Constants

This section is empty.

Variables

View Source
var ErrSVG = errors.New("can't show SVG images in the terminal")

ErrSVG is returned by Decode for SVG images, which it can't draw.

Functions

func Decode

func Decode(data []byte) (image.Image, error)

Decode decodes a PNG, JPEG or GIF, or an asciinema cast. An animated GIF or a cast gives its last frame, which for a recording is how the session ended.

func Fit

func Fit(img image.Image, cols, rows int) (w, h int)

Fit returns the size, in terminal cells, to draw img as half blocks within cols by rows, keeping its shape. Each cell is two pixels tall.

func HalfBlocks

func HalfBlocks(img image.Image, cols, rows int) string

HalfBlocks draws img within cols by rows cells as lines of ▀, each cell showing two pixels with 24-bit colors. Transparent parts show the terminal's background.

func Load

func Load(link string) (image.Image, error)

Load reads the image at link: a file path or a data: URI.

func Show

func Show(w io.Writer, p Protocol, img image.Image, cols int) error

Show writes img to w, at most cols cells wide, through p.

Types

type Protocol

type Protocol int

Protocol is a way to show an image at full resolution.

const (
	None Protocol = iota
	Kitty
	ITerm2
	Sixel
)

func Detect

func Detect(env func(string) string) Protocol

Detect guesses the terminal's image protocol from its environment: kitty and Ghostty speak kitty's, iTerm2 and WezTerm iTerm2's, and terminals that say so in TERM, or are known to, sixel.

Jump to

Keyboard shortcuts

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