Documentation
¶
Index ¶
- Variables
- func GetExtForMime(fileType string) string
- func IsMimeTypeSupported(m string) bool
- func ParseResolution(s string) (image.Rectangle, error)
- type DefinableProcessor
- type Encoder
- type Generator
- type GifEncoder
- type GifGenerator
- type JpegEncoder
- type Manager
- type PngEncoder
- type Processor
- type Request
- type Resolutions
- type SimpleGenerator
- type SimpleManager
Constants ¶
This section is empty.
Variables ¶
var ( // SupportedMimeTypes contains an all mimetypes which are supported by the thumbnailer. SupportedMimeTypes = map[string]struct{}{ "image/png": {}, "image/jpg": {}, "image/jpeg": {}, "image/gif": {}, "image/bmp": {}, "image/x-ms-bmp": {}, "image/tiff": {}, "text/plain": {}, "audio/flac": {}, "audio/mpeg": {}, "audio/ogg": {}, "application/vnd.geogebra.slides": {}, "application/vnd.geogebra.pinboard": {}, } )
Functions ¶
func GetExtForMime ¶
GetExtForMime return the supported extension by mime
func IsMimeTypeSupported ¶
IsMimeTypeSupported validate if the mime type is supported
Types ¶
type DefinableProcessor ¶
type DefinableProcessor struct {
Slug string
Converter func(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA
}
DefinableProcessor is the simplest processor, it holds a replaceable image converter function.
func ProcessorFor ¶
func ProcessorFor(id, fileType string) (DefinableProcessor, error)
ProcessorFor returns a matching Processor
func (DefinableProcessor) ID ¶
func (p DefinableProcessor) ID() string
ID returns the processor identification.
func (DefinableProcessor) Process ¶
func (p DefinableProcessor) Process(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA
Process transforms the given image.
type Encoder ¶
type Encoder interface {
// Encode encodes the image to a format.
Encode(w io.Writer, img 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 ¶
EncoderForType returns the encoder for a given file type or nil if the type is not supported.
type Generator ¶
type Generator interface {
Generate(size image.Rectangle, img interface{}) (interface{}, error)
Dimensions(img interface{}) (image.Rectangle, error)
ProcessorID() string
}
Generator generates a web friendly file version.
func GeneratorFor ¶
GeneratorFor returns the generator for a given file type or nil if the type is not supported.
type GifEncoder ¶
type GifEncoder struct{}
GifEncoder encodes to gif
func (GifEncoder) Encode ¶
func (e GifEncoder) Encode(w io.Writer, img interface{}) error
Encode encodes the image to a gif format
func (GifEncoder) MimeType ¶
func (e GifEncoder) MimeType() string
MimeType returns the mimetype used by the encoder.
func (GifEncoder) Types ¶
func (e GifEncoder) Types() []string
Types returns the supported types of the GifEncoder
type GifGenerator ¶
type GifGenerator struct {
// contains filtered or unexported fields
}
GifGenerator is used to create a web friendly version of the provided gif image.
func NewGifGenerator ¶
func NewGifGenerator(filetype, process string) (GifGenerator, error)
func (GifGenerator) Dimensions ¶
func (g GifGenerator) Dimensions(img interface{}) (image.Rectangle, error)
func (GifGenerator) Generate ¶
func (g GifGenerator) Generate(size image.Rectangle, img interface{}) (interface{}, error)
Generate generates a alternative gif version.
func (GifGenerator) ProcessorID ¶
func (g GifGenerator) ProcessorID() string
ProcessorID returns the processor identification.
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.
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(r Request, img 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(r 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.
type Processor ¶
type Processor interface {
ID() string
Process(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA
}
Processor processes the thumbnail by applying different transformations to it.
type Request ¶
type Request struct {
Resolution image.Rectangle
Encoder Encoder
Generator Generator
Checksum string
}
Request bundles information needed to generate a thumbnail for a file
type Resolutions ¶
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 ¶
type SimpleGenerator struct {
// contains filtered or unexported fields
}
SimpleGenerator is the default image generator and is used for all image types expect gif.
func NewSimpleGenerator ¶
func NewSimpleGenerator(filetype, process string) (SimpleGenerator, error)
func (SimpleGenerator) Dimensions ¶
func (g SimpleGenerator) Dimensions(img interface{}) (image.Rectangle, error)
func (SimpleGenerator) Generate ¶
func (g SimpleGenerator) Generate(size image.Rectangle, img interface{}) (interface{}, error)
Generate generates a alternative image version.
func (SimpleGenerator) ProcessorID ¶
func (g SimpleGenerator) ProcessorID() string
ProcessorID returns the processor identification.
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, maxInputWidth, maxInputHeight int) SimpleManager
NewSimpleManager creates a new instance of SimpleManager
func (SimpleManager) CheckThumbnail ¶
func (s SimpleManager) CheckThumbnail(r Request) (string, bool)
CheckThumbnail checks if a thumbnail with the requested attributes exists.
func (SimpleManager) Generate ¶
func (s SimpleManager) Generate(r Request, img interface{}) (string, error)
Generate creates a thumbnail and stores it
func (SimpleManager) GetThumbnail ¶
func (s SimpleManager) GetThumbnail(key string) ([]byte, error)
GetThumbnail will load the thumbnail from the storage and return its content.