encoder

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 9 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 encoder provides the encoder registration mechanisms for iv.

An encoder writes a decoded image to a writer, either as a file format (png, jpeg, webp) or as terminal graphics.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotRegistered is returned when no encoder is registered under a name.
	ErrNotRegistered = errors.New("encoder not registered")
	// ErrUnsupportedFormat is returned when an encoder is registered but the
	// underlying library was not built with support for its output format.
	ErrUnsupportedFormat = errors.New("format not supported by this build")
)

Functions

func Encode

func Encode(ctx context.Context, w io.Writer, name string, img image.Image) error

Encode encodes the image to the writer using the named encoder.

func Names

func Names() []string

Names returns the sorted names of every registered encoder.

func Unregister

func Unregister(name string) bool

Unregister removes the named encoder. Returns whether it was registered. Not used by iv itself; provided for tests.

Types

type EncodeFunc

type EncodeFunc func(context.Context, io.Writer, image.Image) error

EncodeFunc encodes an image to a writer.

type Entry

type Entry struct {
	// Name is the unique encoder name.
	Name string
	// Desc is the human readable description.
	Desc string
	// Ext is the output file extension, without a leading dot. Empty for
	// terminal encoders.
	Ext string
	// Term indicates the encoder writes terminal graphics rather than a file
	// format.
	Term bool
	// contains filtered or unexported fields
}

Entry is a registered iv image encoder.

func All

func All() []*Entry

All returns every registered encoder, ordered by name.

func ForExt

func ForExt(ext string) (*Entry, bool)

ForExt returns the encoder producing the file extension, without a leading dot.

func Get

func Get(name string) (*Entry, bool)

Get returns the named encoder.

func Register

func Register(name string, opts ...Option) *Entry

Register registers an encoder. It panics when name is empty or already registered.

func TermEncoders

func TermEncoders() []*Entry

TermEncoders returns the terminal graphics encoders, ordered by name.

func (*Entry) Encode

func (e *Entry) Encode(ctx context.Context, w io.Writer, img image.Image) error

Encode encodes the image to the writer. If the image kept an error while it was encoded (see ivimg.Err), Encode returns that error, because the output then does not show the image.

func (*Entry) String

func (e *Entry) String() string

String satisfies the fmt.Stringer interface.

type Option

type Option func(*Entry)

Option is an encoder option.

func Desc

func Desc(desc string) Option

Desc is an encoder option to set the human readable description.

func Encoder

func Encoder(f EncodeFunc) Option

Encoder is an encoder option to set the encoding func.

func Extension

func Extension(ext string) Option

Extension is an encoder option to set the output file extension, without a leading dot.

func ImageEncoder

func ImageEncoder(f func(io.Writer, image.Image) error) Option

ImageEncoder is an encoder option setting the encoding func from a plain image encoder, such as [png.Encode]. The encoder gets the pixels under each wrapper of the image (see ivimg.Unwrap), because the encoders of the standard library are fast only for their own concrete types.

func Term

func Term() Option

Term is an encoder option marking the encoder as writing terminal graphics.

Directories

Path Synopsis
Package all registers every iv encoder.
Package all registers every iv encoder.
Package jpeg supplies a jpeg encoder for iv.
Package jpeg supplies a jpeg encoder for iv.
Package nativewebp supplies a webp encoder for iv.
Package nativewebp supplies a webp encoder for iv.
Package pdf supplies a pdf encoder for iv, wrapping any decoded image in a pdf document.
Package pdf supplies a pdf encoder for iv, wrapping any decoded image in a pdf document.
Package png supplies a png encoder for iv.
Package png supplies a png encoder for iv.
Package rasterm supplies the terminal graphics encoder for iv.
Package rasterm supplies the terminal graphics encoder for iv.
Package vips supplies libvips backed encoders for iv, covering the output formats the Go encoders do not handle.
Package vips supplies libvips backed encoders for iv, covering the output formats the Go encoders do not handle.

Jump to

Keyboard shortcuts

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