encode

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Overview

Package encode provides methods for encoding images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterEncoder

func RegisterEncoder(ctx context.Context, f InitializeEncoderFunc, schemes ...string) error

RegisterEncoder registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Encoder` instances by the `NewEncoder` method.

Types

type Encoder

type Encoder interface {
	// Encode encode and writes an `image.Image` instance to a `io.Writer` instance.
	Encode(context.Context, io.Writer, image.Image) error
}

Encoder is an interface for writing data to multiple sources or targets.

func NewEncoder

func NewEncoder(ctx context.Context, uri string) (Encoder, error)

NewEncoder returns a new `Encoder` instance configured by 'uri'. The value of 'uri' is parsed as a `url.URL` and its scheme is used as the key for a corresponding `EncoderInitializationFunc` function used to instantiate the new `Encoder`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterEncoder` method.

func NewGIFEncoder

func NewGIFEncoder(ctx context.Context, uri string) (Encoder, error)

NewGIFEncoder returns a new `GIFEncoder` instance. 'uri' in the form of:

/path/to/image.gif

func NewJPEGEncoder

func NewJPEGEncoder(ctx context.Context, uri string) (Encoder, error)

NewJPEGEncoder returns a new `JPEGEncoder` instance. 'uri' in the form of:

/path/to/image.jpg?{OPTIONS}

Where {OPTIONS} are:

  • ?quality={QUALITY} - an optional value specifying the quality of the JPEG image; default is 100.

func NewPNGEncoder

func NewPNGEncoder(ctx context.Context, uri string) (Encoder, error)

NewPNGEncoder returns a new `PNGEncoder` instance. 'uri' in the form of:

/path/to/image.jpg

type GIFEncoder

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

GIFEncoder is a struct that implements the `Encoder` interface for encoding GIF images.

func (*GIFEncoder) Encode

func (e *GIFEncoder) Encode(ctx context.Context, wr io.Writer, im image.Image) error

Encode will encode 'im' using the `image/gif` package and write the results to 'wr'

type InitializeEncoderFunc

type InitializeEncoderFunc func(context.Context, string) (Encoder, error)

EncoderInitializationFunc is a function defined by individual encoder package and used to create an instance of that encoder.

type JPEGEncoder

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

JPEGEncoder is a struct that implements the `Encoder` interface for encoding JPEG images.

func (*JPEGEncoder) Encode

func (e *JPEGEncoder) Encode(ctx context.Context, wr io.Writer, im image.Image) error

Encode will encode 'im' using the `image/jpeg` package and write the results to 'wr'

type PNGEncoder

type PNGEncoder struct {
	Encoder
}

PNGEncoder is a struct that implements the `Encoder` interface for encoding PNG images.

func (*PNGEncoder) Encode

func (e *PNGEncoder) Encode(ctx context.Context, wr io.Writer, im image.Image) error

Encode will encode 'im' using the `image/png` package and write the results to 'wr'

Jump to

Keyboard shortcuts

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