encoder

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 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")
)

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) EncodeSource added in v0.24.0

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

EncodeSource writes the decoded image to the writer, before the image is scaled and composited, when the encoder takes it as it is (see Source). It returns false when the encoder does not take it, and has then written nothing. The image is then prepared, and given to Entry.Encode.

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 Source added in v0.24.0

func Source(f SourceFunc) Option

Source is an encoder option to set the func that writes a decoded image before it is scaled and composited. See Entry.EncodeSource.

func Term

func Term() Option

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

type SourceFunc added in v0.24.0

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

SourceFunc writes a decoded image to a writer before the image is scaled and composited, such as a document that keeps its vectors. It returns false when it does not take the image, and has then written nothing.

Directories

Path Synopsis
Package all registers every iv encoder.
Package all registers every iv encoder.
Package avif supplies an avif encoder for iv, in pure Go.
Package avif supplies an avif encoder for iv, in pure Go.
Package gif supplies a gif encoder for iv, in Go.
Package gif supplies a gif encoder for iv, in Go.
Package heic supplies a heic encoder for iv, in pure Go.
Package heic supplies a heic encoder for iv, in pure Go.
Package jpeg supplies a jpeg encoder for iv.
Package jpeg supplies a jpeg encoder for iv.
Package jpeg2000 supplies a jpeg 2000 encoder for iv, in pure Go.
Package jpeg2000 supplies a jpeg 2000 encoder for iv, in pure Go.
Package jxl supplies a jpeg xl encoder for iv, in pure Go.
Package jxl supplies a jpeg xl encoder for iv, in pure Go.
Package pdf supplies a pdf encoder for iv.
Package pdf supplies a pdf encoder for iv.
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 tiff supplies a tiff encoder for iv, in Go.
Package tiff supplies a tiff encoder for iv, in Go.
Package webp supplies the webp encoders for iv, in pure Go (D63).
Package webp supplies the webp encoders for iv, in pure Go (D63).

Jump to

Keyboard shortcuts

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