decode

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: BSD-3-Clause Imports: 12 Imported by: 3

Documentation

Overview

Package decode provides methods for decoding images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeFromPath

func DecodeFromPath(ctx context.Context, path string) (image.Image, string, error)

func RegisterDecoder

func RegisterDecoder(ctx context.Context, f InitializeDecoderFunc, schemes ...string) error

RegisterDecoder registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Decoder` instances by the `NewDecoder` method.

Types

type Decoder

type Decoder interface {
	// Decode decodes an `io.ReaderSeeker` instance and returns an `image.Image` instance.
	Decode(context.Context, io.ReadSeeker) (image.Image, string, error)
}

func NewDecoder

func NewDecoder(ctx context.Context, uri string) (Decoder, error)

NewDecoder returns a new `Decoder` 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 `DecoderInitializationFunc` function used to instantiate the new `Decoder`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterDecoder` method.

func NewGIFDecoder

func NewGIFDecoder(ctx context.Context, uri string) (Decoder, error)

NewGIFDecoder returns a new `GIFDecoder` instance. 'uri' in the form of:

/path/to/image.gif

func NewJPEGDecoder

func NewJPEGDecoder(ctx context.Context, uri string) (Decoder, error)

NewJPEGDecoder returns a new `JPEGDecoder` instance. 'uri' in the form of:

/path/to/image.jpg

func NewPNGDecoder

func NewPNGDecoder(ctx context.Context, uri string) (Decoder, error)

NewPNGDecoder returns a new `PNGDecoder` instance. 'uri' in the form of:

/path/to/image.png

type GIFDecoder

type GIFDecoder struct {
	Decoder
}

GIFDecoder is a struct that implements the `Decoder` interface for decoding GIF image.

func (*GIFDecoder) Decode

func (e *GIFDecoder) Decode(ctx context.Context, r io.ReadSeeker) (image.Image, string, error)

Decode will decode the body of 'r' in to an `image.Image` instance using the `image/gif` package.

type InitializeDecoderFunc

type InitializeDecoderFunc func(context.Context, string) (Decoder, error)

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

type JPEGDecoder

type JPEGDecoder struct {
	Decoder
}

JPEGDecoder is a struct that implements the `Decoder` interface for decoding JPEG image.

func (*JPEGDecoder) Decode

func (e *JPEGDecoder) Decode(ctx context.Context, r io.ReadSeeker) (image.Image, string, error)

Decode will decode the body of 'r' in to an `image.Image` instance using the `image/jpeg` package.

type PNGDecoder

type PNGDecoder struct {
	Decoder
}

PNGDecoder is a struct that implements the `Decoder` interface for decoding PNG image.

func (*PNGDecoder) Decode

func (e *PNGDecoder) Decode(ctx context.Context, r io.ReadSeeker) (image.Image, string, error)

Decode will decode the body of 'r' in to an `image.Image` instance using the `image/png` package.

Jump to

Keyboard shortcuts

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