thumbnail

package
v0.0.0-...-499b85e Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SupportedMimeTypes = [...]string{
		"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, image.Image) 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

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

type JpegEncoder

type JpegEncoder struct{}

JpegEncoder encodes to jpg.

func (JpegEncoder) Encode

func (e JpegEncoder) Encode(w io.Writer, i image.Image) 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 will return a thumbnail for a file
	Generate(Request, image.Image) ([]byte, error)
	// Get loads the thumbnail from the storage.
	// It will return nil if no image is stored for the given context.
	Get(Request) ([]byte, bool)
}

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, i image.Image) 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
	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 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) Generate

func (s SimpleManager) Generate(r Request, img image.Image) ([]byte, error)

Generate creates a thumbnail and stores it. The created thumbnail is also being returned.

func (SimpleManager) Get

func (s SimpleManager) Get(r Request) ([]byte, bool)

Get tries to get the stored thumbnail and return it. If there is no cached thumbnail it will return nil

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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