thumbnail

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidType represents the error when a type can't be encoded.
	ErrInvalidType = errors.New("can't encode this type")
	// ErrNoEncoderForType represents the error when an encoder couldn't be found for a type.
	ErrNoEncoderForType = errors.New("no encoder for this type found")
)
View Source
var (
	// ErrInvalidType represents the error when a type can't be encoded.
	ErrInvalidType2 = errors.New("can't encode this type")
	// ErrNoGeneratorForType represents the error when no generator could be found for a type.
	ErrNoGeneratorForType = errors.New("no generator for this type found")
)
View Source
var (
	// SupportedMimeTypes contains a all mimetypes which are supported by the thumbnailer.
	SupportedMimeTypes = map[string]struct{}{
		"image/png":  {},
		"image/jpg":  {},
		"image/jpeg": {},
		"image/gif":  {},
		"text/plain": {},
	}
)

Functions

func IsMimeTypeSupported

func IsMimeTypeSupported(m string) bool

func ParseResolution

func ParseResolution(s string) (image.Rectangle, error)

ParseResolution returns an image.Rectangle representing the resolution given as a string

Types

type Encoder

type Encoder interface {
	// Encode encodes the image to a format.
	Encode(io.Writer, interface{}) error
	// Types returns the formats suffixes.
	Types() []string
	// MimeType returns the mimetype used by the encoder.
	MimeType() string
}

Encoder encodes the thumbnail to a specific format.

func EncoderForType

func EncoderForType(fileType string) (Encoder, error)

EncoderForType returns the encoder for a given file type or nil if the type is not supported.

type Generator added in v1.19.0

type Generator interface {
	GenerateThumbnail(image.Rectangle, interface{}) (interface{}, error)
}

func GeneratorForType added in v1.19.0

func GeneratorForType(fileType string) (Generator, error)

GeneratorForType returns the generator for a given file type or nil if the type is not supported.

type GifEncoder added in v1.19.0

type GifEncoder struct{}

func (GifEncoder) Encode added in v1.19.0

func (e GifEncoder) Encode(w io.Writer, img interface{}) error

func (GifEncoder) MimeType added in v1.19.0

func (e GifEncoder) MimeType() string

func (GifEncoder) Types added in v1.19.0

func (e GifEncoder) Types() []string

type GifGenerator added in v1.19.0

type GifGenerator struct{}

func (GifGenerator) GenerateThumbnail added in v1.19.0

func (g GifGenerator) GenerateThumbnail(size image.Rectangle, img interface{}) (interface{}, error)

type JpegEncoder

type JpegEncoder struct{}

JpegEncoder encodes to jpg.

func (JpegEncoder) Encode

func (e JpegEncoder) Encode(w io.Writer, img interface{}) error

Encode encodes to jpg

func (JpegEncoder) MimeType

func (e JpegEncoder) MimeType() string

MimeType returns the mimetype for jpg files.

func (JpegEncoder) Types

func (e JpegEncoder) Types() []string

Types returns the jpg suffixes.

type Manager

type Manager interface {
	// Generate creates a thumbnail and stores it.
	// The function returns a key with which the actual file can be retrieved.
	Generate(Request, interface{}) (string, error)
	// CheckThumbnail checks if a thumbnail with the requested attributes exists.
	// The function will return a status if the file exists and the key to the file.
	CheckThumbnail(Request) (string, bool)
	// GetThumbnail will load the thumbnail from the storage and return its content.
	GetThumbnail(key string) ([]byte, error)
}

Manager is responsible for generating thumbnails

type PngEncoder

type PngEncoder struct{}

PngEncoder encodes to png

func (PngEncoder) Encode

func (e PngEncoder) Encode(w io.Writer, img interface{}) error

Encode encodes to png format

func (PngEncoder) MimeType

func (e PngEncoder) MimeType() string

MimeType returns the mimetype for png files.

func (PngEncoder) Types

func (e PngEncoder) Types() []string

Types returns the png suffix

type Request

type Request struct {
	Resolution image.Rectangle
	Encoder    Encoder
	Generator  Generator
	Checksum   string
}

Request bundles information needed to generate a thumbnail for afile

type Resolutions

type Resolutions []image.Rectangle

Resolutions is a list of image.Rectangle representing resolutions.

func ParseResolutions

func ParseResolutions(strs []string) (Resolutions, error)

ParseResolutions creates an instance of Resolutions from resolution strings.

func (Resolutions) ClosestMatch

func (rs Resolutions) ClosestMatch(requested image.Rectangle, sourceSize image.Rectangle) image.Rectangle

ClosestMatch returns the resolution which is closest to the provided resolution. If there is no exact match the resolution will be the next higher one. If the given resolution is bigger than all available resolutions the biggest available one is used.

type SimpleGenerator added in v1.19.0

type SimpleGenerator struct{}

func (SimpleGenerator) GenerateThumbnail added in v1.19.0

func (g SimpleGenerator) GenerateThumbnail(size image.Rectangle, img interface{}) (interface{}, error)

type SimpleManager

type SimpleManager struct {
	// contains filtered or unexported fields
}

SimpleManager is a simple implementation of Manager

func NewSimpleManager

func NewSimpleManager(resolutions Resolutions, storage storage.Storage, logger log.Logger) SimpleManager

NewSimpleManager creates a new instance of SimpleManager

func (SimpleManager) CheckThumbnail added in v1.19.0

func (s SimpleManager) CheckThumbnail(r Request) (string, bool)

func (SimpleManager) Generate

func (s SimpleManager) Generate(r Request, img interface{}) (string, error)

func (SimpleManager) GetThumbnail added in v1.19.0

func (s SimpleManager) GetThumbnail(key string) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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