img

package
v8.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheTTL int

CacheTTL is the number of seconds that will be written to max-age HTTP header

Log is the logger that could be overridden. Should implement interface glogi.Logger. By default is using glogi.SimpleLogger.

View Source
var SaveDataEnabled = true

SaveDataEnabled is the flag to enable/disable Save-Data client hint. Sometime CDN doesn't support Save-Data in Vary response header in which case you would need to set this to false

Functions

This section is empty.

Types

type Cmd

type Cmd func(input *TransformationConfig) (*Image, error)

type Command

type Command struct {
	Transformation Cmd
	Config         *TransformationConfig
	Resp           http.ResponseWriter
	Result         *Image
	FinishedCond   *sync.Cond
	Finished       bool
	Err            error
}

type Image

type Image struct {
	// Id of the image mainly used for debugging purposes.
	// Could be a URL of the image or a filename.
	Id       string
	Data     []byte
	MimeType string
}

type Info

type Info struct {
	Format  string
	Quality int
	Opaque  bool
	Width   int
	Height  int
	// Illustration is a flag set on PNG images.
	// If set to true then the image is an illustration, logo or
	// drawing and lossless compression would be preferable.
	// Otherwise, it's most likely a photo and lossy compression
	// could be used.
	Illustration bool
	// Size is the size of the image in bytes
	Size int64
}

Info holds basic information about an image. Fixme: It is really an internal structure for Fixme: a processor, but currently used in GetAdditionalArgs() call.

type Loader

type Loader interface {
	// Load loads an image from the given source.
	//
	// ctx is the context of the current transaction. Typically, it's a context
	// of an incoming HTTP request, so we make it possible to pass values through middlewares.
	//
	// Returns an image.
	Load(src string, ctx context.Context) (*Image, error)
}

Loader is responsible for loading an original image for transformation

type OpCallback

type OpCallback func()

type Processor

type Processor interface {
	// Resize resizes given image preserving aspect ratio.
	// Format of the size argument is width'x'height.
	// Any dimension could be skipped.
	// For example:
	//* 300x200
	//* 300 - only width
	//* x200 - only height
	Resize(input *TransformationConfig) (*Image, error)

	// FitToSize resizes given image cropping it to the given size and does not respect aspect ratio.
	// Format of the size string is width'x'height, e.g. 300x400.
	FitToSize(input *TransformationConfig) (*Image, error)

	// Optimise optimises given image to reduce size of the served image.
	Optimise(input *TransformationConfig) (*Image, error)
}

Processor is the interface for transforming/optimising images.

Each function accepts original image and a list of supported output format by client. Each format should be a MIME type, e.g. image/png, image/webp. The output image will be encoded in one of those formats.

type Quality

type Quality int
const (
	DEFAULT Quality = 1 + iota
	LOW
	LOWER
)

type Queue

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

func NewQueue

func NewQueue() *Queue

func (*Queue) AddAndWait

func (q *Queue) AddAndWait(op *Command, callback OpCallback)

type ResizeConfig

type ResizeConfig struct {
	// Size is a size of output images in the format WxH.
	Size string
}

type Service

type Service struct {
	Loader    Loader
	Processor Processor
	Q         []*Queue
	// contains filtered or unexported fields
}

func NewService

func NewService(r Loader, p Processor, procNum int) (*Service, error)

func (*Service) AsIs

func (r *Service) AsIs(resp http.ResponseWriter, req *http.Request)

func (*Service) FitToSizeUrl

func (r *Service) FitToSizeUrl(resp http.ResponseWriter, req *http.Request)

func (*Service) GetRouter

func (r *Service) GetRouter() *mux.Router

func (*Service) OptimiseUrl

func (r *Service) OptimiseUrl(resp http.ResponseWriter, req *http.Request)

func (*Service) ResizeUrl

func (r *Service) ResizeUrl(resp http.ResponseWriter, req *http.Request)

type TransformationConfig

type TransformationConfig struct {
	// Src is the source image to transform.
	// This field is required for transformations.
	Src *Image
	// SupportedFormats is the list of output formats supported by client.
	// Processor will use one of those formats for result image. If list
	// is empty the format of the source image will be used.
	SupportedFormats []string
	// Quality defines quality of output image
	Quality Quality
	// TrimBorder is a flag whether we need to remove border or not
	TrimBorder bool
	// Config is the configuration for the specific transformation
	Config interface{}
}

TransformationConfig is a configuration passed to Processor that used during transformations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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