images

package
v0.0.0-...-c1b5b8d Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCacheDir

func WithCacheDir(dir string) optFunc

WithCacheDir sets the cache directory

func WithCacheMaxNum

func WithCacheMaxNum(num int) optFunc

WithCacheMaxNum sets the cache max number option

func WithCacheMaxSize

func WithCacheMaxSize(size size.S) optFunc

WithCacheMaxSize sets the cache max size.size option

func WithCreateDirs

func WithCreateDirs(b bool) optFunc

WithCreateDirs sets the create directories option

func WithImageDefaults

func WithImageDefaults(id ImageDefaults) optFunc

WithImageDefaults sets defaults used when no preset or parameters are given

func WithImagePresets

func WithImagePresets(presets []ImagePreset) optFunc

WithImagePresets adds the given set of presets to the handler

func WithLogLevel

func WithLogLevel(s string) optFunc

WithLogLevel sets the log level

func WithLogger

func WithLogger(l *log.Logger) optFunc

WithLogger sets the logger

func WithOriginalsDir

func WithOriginalsDir(dir string) optFunc

WithOriginalsDir sets the originals directory

func WithSetPermissions

func WithSetPermissions(b bool) optFunc

WithSetPermissions sets the set permissions option

Types

type CacheStat

type CacheStat struct {
	NumItems  int
	Capacity  int
	Size      size.S
	Hit       uint32
	Miss      uint32
	Evictions uint32
}

type ErrIdNotFound

type ErrIdNotFound struct {
	IdGiven int
	Err     error
}

func (ErrIdNotFound) Error

func (e ErrIdNotFound) Error() string

func (ErrIdNotFound) Is

func (e ErrIdNotFound) Is(err error) bool

type Format

type Format string

Format represents image formats.

const (
	Jpeg Format = "jpeg" // quality 1-100
	Png  Format = "png"  // always lossless
	Gif  Format = "gif"  // num colors 1-256
)

func ParseFormat

func ParseFormat(s string) (Format, error)

func (Format) String

func (f Format) String() string

type ImageDefaults

type ImageDefaults struct {
	Format      Format
	QualityJpeg int
	QualityGif  int
	Width       int
	Height      int
	MaxSize     size.S
	Interpolation
}

func (ImageDefaults) String

func (id ImageDefaults) String() string

type ImageHandler

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

ImageHandler is the main type of this package.

func New

func New(optFuncs ...optFunc) (*ImageHandler, error)

New creates a new Imageandler and applies the given options.

TODO: MUST create a cache based on files in cache folder on startup

func (*ImageHandler) Add

func (h *ImageHandler) Add(r io.Reader) (int, error)

Returns id of the added image

func (*ImageHandler) Delete

func (h *ImageHandler) Delete(id int) error

func (*ImageHandler) Get

func (h *ImageHandler) Get(params ImageParameters) (string, error)

returns the path to the processed image.

func (*ImageHandler) GetPreset

func (h *ImageHandler) GetPreset(preset string) (ImagePreset, bool)

func (*ImageHandler) Ids

func (h *ImageHandler) Ids() ([]int, error)

TODO: page and chunk as arguments for when we have thousands of ids?

func (*ImageHandler) Stat

func (h *ImageHandler) Stat() (Stat, error)

func (*ImageHandler) StatId

func (h *ImageHandler) StatId(id int) (ImageStat, error)

type ImageParameters

type ImageParameters struct {
	Id int

	Format

	// Jpeg:1-100, Gif:1-256
	Quality int

	// width and Height in pixels (0 = keep aspect ratio, both width and height can not be 0)
	Width  uint
	Height uint

	// Max file-size in bytes (0 = no limit)
	MaxSize size.S
}

func (*ImageParameters) String

func (ip *ImageParameters) String() string

type ImagePreset

type ImagePreset struct {
	Name    string
	Alias   []string
	Format  Format
	Quality int
	Width   int
	Height  int
	MaxSize size.S
	Interpolation
}

func (ImagePreset) String

func (ip ImagePreset) String() string

type ImageStat

type ImageStat struct {
	Id           int
	OriginalSize size.S
	CacheSize    size.S
	CacheNum     int
}

type Interpolation

type Interpolation string

Interpolation represents interpolation methods used when resizing images.

const (
	NearestNeighbor Interpolation = "nearestNeighbor"
	Bilinear        Interpolation = "bilinear"
	Bicubic         Interpolation = "bicubic"
	MitchellNetrav  Interpolation = "MitchellNetravali"
	Lanczos2        Interpolation = "lanczos2"
	Lanczos3        Interpolation = "lanczos3"
)

func ParseInterpolation

func ParseInterpolation(s string) (Interpolation, error)

func (Interpolation) String

func (r Interpolation) String() string

type Logger

type Logger interface {
	Debug(msg any, keyvals ...any)
	Info(msg any, keyvals ...any)
	Warn(msg any, keyvals ...any)
	Error(msg any, keyvals ...any)
	Fatal(msg any, keyvals ...any)
}

type Stat

type Stat struct {
	Ids      []int
	SizeOrig size.S
	Cache    CacheStat
}

type SubImager

type SubImager interface {
	SubImage(r image.Rectangle) image.Image
}

Jump to

Keyboard shortcuts

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