sixel

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 14 Imported by: 66 modules, 46 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.

README

go-sixel

DRCS Sixel Encoder/Decoder for Go

Requirements

  • Go 1.24 or later
  • A sixel-compatible terminal (see Supported Terminals)
  • ffmpeg and ffprobe (only for gosvideo)

Supported Terminals

Sixel is a bitmap graphics protocol. The following terminals are known to support sixel output:

Installation

Library
go get github.com/mattn/go-sixel
Commands
go install github.com/mattn/go-sixel/cmd/gosr@latest
go install github.com/mattn/go-sixel/cmd/gosd@latest
go install github.com/mattn/go-sixel/cmd/gosgif@latest
go install github.com/mattn/go-sixel/cmd/gosvideo@latest
Command Description
gosr Image renderer
gosd Decoder to PNG
goscat Render cats
gosgif Render animation GIF
gosvideo Render video via ffmpeg
gosl Run SL

Usage

Render an image
$ gosr foo.png

Or from stdin:

$ cat foo.png | gosr -
Decode sixel to PNG
$ cat foo.drcs | gosd > foo.png
Render an animation GIF
$ gosgif nyacat.gif
Play a video
$ gosvideo movie.mp4
$ gosvideo -width 320 -fps 15 -loop clip.mp4
$ gosvideo -colors 255 -dither movie.mp4

gosvideo requires ffmpeg and ffprobe in your PATH. Default playback is tuned for speed with -colors 64 and dithering disabled.

Use as a library
img, _, _ := image.Decode(filename)
sixel.NewEncoder(os.Stdout).Encode(img)

License

MIT

Author

Yasuhiro Matsumoto (a.k.a mattn)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellSize added in v0.0.14

func CellSize() (width, height int, err error)

CellSize returns the size in pixels of a character cell of the controlling terminal. It asks the terminal for the cell size (XTWINOPS 16) and, if that is not answered, divides the text area size in pixels (XTWINOPS 14) by the size in characters (XTWINOPS 18).

func IsSupported added in v0.0.13

func IsSupported() bool

IsSupported reports whether the controlling terminal can render sixel graphics. It sends a Primary Device Attributes query (DA1, ESC [ c) to the terminal and checks whether the reply advertises sixel support (attribute 4). It returns false when there is no terminal or the terminal does not reply in time.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decode sixel format into image

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder return new instance of Decoder

func (*Decoder) Decode

func (e *Decoder) Decode(img *image.Image) error

Decode do decoding from image

type Encoder

type Encoder struct {

	// Dither, if true, will dither the image when generating a paletted version
	// using the Floyd–Steinberg dithering algorithm.
	Dither bool

	// Width is the maximum width to draw to.
	Width int
	// Height is the maximum height to draw to.
	Height int

	// Colors sets the number of colors for the encoder to quantize if needed.
	// If the value is below 2 (e.g. the zero value), then 256 is used.
	// A color is always reserved for alpha, so 2 colors give you 1 color.
	Colors int

	// Transparent, if true, leaves the existing screen content visible
	// behind pixels with zero alpha (DECSIXEL P2=1). By default they are
	// painted in the terminal's background color (P2=0).
	Transparent bool

	// Palette, if non-nil, is used for quantization instead of computing an
	// adaptive palette for every image. The nearest-color lookup table is
	// built once and cached across Encode calls, which makes encoding many
	// similar images (e.g. video frames) much faster. It may hold at most
	// 255 colors (one register is reserved for transparency) and takes
	// precedence over Colors.
	Palette color.Palette
	// contains filtered or unexported fields
}

Encoder encode image to sixel format

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder return new instance of Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(img image.Image) error

Encode do encoding

Directories

Path Synopsis
cmd
goscat command
gosd command
gosgif command
gosl command
gosr command
gostube command
gosvideo command

Jump to

Keyboard shortcuts

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