package imgcat

import "github.com/campoy/tools/imgcat"

Package imgcat provides a writer useful to show images directly into iterm2.

imgcat.go

IsSupported check whether imgcat works in the current terminal.

❖ type Encoder struct { // contains filtered or unexported fields }

An Encoder is used to encode images to iterm2.

❖ func NewEncoder(w io.Writer, options ...Option) (*Encoder, error)

NewEncoder returns a encoder that encodes images for iterm2.

Example Code: enc, err := imgcat.NewEncoder(os.Stdout, imgcat.Width(imgcat.Pixels(100)), imgcat.Inline(true), imgcat.Name("smiley.png")) if err != nil { log.Fatal(err) } f, err := os.Open("testdata/icon.png") if err != nil { log.Fatal(err) } defer func() { _ = f.Close() }() // Display the image in the terminal. if err := enc.Encode(f); err != nil { log.Fatal(err) }

Encode encodes the given image into the output.

Writer creates a writer that will encode whatever is written to it.

❖ type Length string

Length is used by the Width and Height options.

Auto keeps the image to its inherent size.

Cells gives a length in character cells.

Percent gives relative length to the session's width or height.

Pixels gives a length in pixels.

❖ type Option string

An Option modifies how an image is displayed.

Height to render, it can be in cells, pixels, percentage, or auto.

Inline set to true causes the to be displayed inline. Otherwise, it will be downloaded with no visual representation in the terminal session. Defaults to false.

Name sents the filename for the image. Defaults to "Unnamed file".

PreserveAspectRatio set to false causes the image's inherent aspect ratio will not be respected; otherwise, it will fill the specified width and height as much as possible without stretching. Defaults to true.

Size sets the file size in bytes. It's only used by the progress indicator.

Width to render, it can be in cells, pixels, percentage, or auto.

Path Synopsis imgcat