core

package
v0.0.0-...-0361b98 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIterations = 4

Variables

View Source
var FileMutex sync.Map
View Source
var HttpCacheMutex sync.Map

Functions

func BuildResponse

func BuildResponse(w http.ResponseWriter, imagePath string, contentType string) error

func CompressByDSSIM

func CompressByDSSIM(original *image.Image, newImgFile io.Writer, handler *ImageHandler, threshold float64) error

func Dispatch

func Dispatch(request *http.Request, response *http.Response, imageParameters *ImageParameters, options *Options) (string, string, error)

func DownloadImage

func DownloadImage(originalUrl string, cacheDelay int, allowed_domains []string) (*http.Response, error)

func GetAllImageHandlers

func GetAllImageHandlers() map[string]ImageHandler

func GetAllImageHandlersByExtension

func GetAllImageHandlersByExtension() map[string]ImageHandler

func IsImage

func IsImage(response *http.Response) bool

func Optimize

func Optimize(response *http.Response, imageParameters *ImageParameters, options *Options) (string, string, error)

func RemoveImageHandlerFromAutoConf

func RemoveImageHandlerFromAutoConf(autoConfPath string, imageType string) error

func StartHttpCachePurge

func StartHttpCachePurge(checkIntervalSeconds int) chan bool

Types

type AvifHandler

type AvifHandler struct {
	ImageHandler
}

func (*AvifHandler) Decode

func (a *AvifHandler) Decode(reader io.Reader) (image.Image, error)

func (*AvifHandler) Encode

func (a *AvifHandler) Encode(newImgFile io.Writer, newImage image.Image, quality uint) error

func (*AvifHandler) ImageExtension

func (a *AvifHandler) ImageExtension() string

func (*AvifHandler) ImageType

func (a *AvifHandler) ImageType() string

func (*AvifHandler) SupportsTransparency

func (a *AvifHandler) SupportsTransparency() bool

type ImageHandler

type ImageHandler interface {
	ImageType() string
	ImageExtension() string
	SupportsTransparency() bool
	Decode(reader io.Reader) (image.Image, error)
	Encode(newImgFile io.Writer, newImage image.Image, quality uint) error
}

func AutoImageHandler

func AutoImageHandler(clientRequest *http.Request, imageResponse *http.Response, autoConfPath string, preferredConverts []string) (ImageHandler, error)

func NewImageHandler

func NewImageHandler(imageType string) (ImageHandler, error)

func NewImageHandlerByBytes

func NewImageHandlerByBytes(buffer io.Reader) (ImageHandler, error)

func NewImageHandlerByExtension

func NewImageHandlerByExtension(extension string) (ImageHandler, error)

type ImageParameters

type ImageParameters struct {
	Width           uint
	Height          uint
	Quality         uint
	AdaptiveQuality bool
	Convert         string
}

ImageParameters represents the parameters for optimization

func Parser

func Parser(name string) (ImageParameters, error)

Parser extracts width, height and quality from the provided parameters.

func (*ImageParameters) GenerateHash

func (imParams *ImageParameters) GenerateHash(response *http.Response) string

func (*ImageParameters) GetUrlString

func (imParams *ImageParameters) GetUrlString() string

type JPEGHandler

type JPEGHandler struct {
	ImageHandler
}

func (*JPEGHandler) Decode

func (j *JPEGHandler) Decode(reader io.Reader) (image.Image, error)

func (*JPEGHandler) Encode

func (j *JPEGHandler) Encode(newImgFile io.Writer, newImage image.Image, quality uint) error

func (*JPEGHandler) ImageExtension

func (j *JPEGHandler) ImageExtension() string

func (*JPEGHandler) ImageType

func (j *JPEGHandler) ImageType() string

func (*JPEGHandler) SupportsTransparency

func (j *JPEGHandler) SupportsTransparency() bool

type OptimizationResult

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

type Options

type Options struct {
	PathTemp, PathMedia string
	Timeout             int
}

type PNGHandler

type PNGHandler struct {
	ImageHandler
}

func (*PNGHandler) Decode

func (p *PNGHandler) Decode(reader io.Reader) (image.Image, error)

func (*PNGHandler) Encode

func (p *PNGHandler) Encode(newImgFile io.Writer, newImage image.Image, quality uint) error

func (*PNGHandler) ImageExtension

func (p *PNGHandler) ImageExtension() string

func (*PNGHandler) ImageType

func (p *PNGHandler) ImageType() string

func (*PNGHandler) SupportsTransparency

func (p *PNGHandler) SupportsTransparency() bool

type WebPHandler

type WebPHandler struct {
	ImageHandler
}

func (*WebPHandler) Decode

func (w *WebPHandler) Decode(reader io.Reader) (image.Image, error)

func (*WebPHandler) Encode

func (w *WebPHandler) Encode(newImgFile io.Writer, newImage image.Image, quality uint) error

func (*WebPHandler) ImageExtension

func (w *WebPHandler) ImageExtension() string

func (*WebPHandler) ImageType

func (w *WebPHandler) ImageType() string

func (*WebPHandler) SupportsTransparency

func (w *WebPHandler) SupportsTransparency() bool

type WebPLosslessHandler

type WebPLosslessHandler struct {
	WebPHandler
}

func (*WebPLosslessHandler) Encode

func (w *WebPLosslessHandler) Encode(newImgFile io.Writer, newImage image.Image, quality uint) error

func (*WebPLosslessHandler) ImageExtension

func (w *WebPLosslessHandler) ImageExtension() string

type WorkerManager

type WorkerManager struct {
	// contains filtered or unexported fields
}
var GlobalWorkerManager *WorkerManager

func NewWorkerManager

func NewWorkerManager() *WorkerManager

func (*WorkerManager) Close

func (w *WorkerManager) Close()

func (*WorkerManager) Dispatch

func (w *WorkerManager) Dispatch(response *http.Response, imageParameters *ImageParameters, options *Options) chan output

func (*WorkerManager) Run

func (w *WorkerManager) Run()

Jump to

Keyboard shortcuts

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