thumb

package
v3.0.0-...-3edb00a Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: GPL-3.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Generators = GeneratorList{}

	ErrPassThrough  = errors.New("pass through")
	ErrNotAvailable = fmt.Errorf("thumbnail not available: %w", ErrPassThrough)
)
View Source
var (
	ErrUnknownGenerator = errors.New("unknown generator type")
	ErrUnknownOutput    = errors.New("unknown output from generator")
)

Functions

func RegisterGenerator

func RegisterGenerator(generator Generator)

RegisterGenerator registers a thumbnail generator.

func Resize

func Resize(newWidth, newHeight uint, img image.Image) image.Image

func TestGenerator

func TestGenerator(ctx context.Context, name, executable string) (string, error)

TestGenerator tests thumb generator by getting lib version

func Thumbnail

func Thumbnail(maxWidth, maxHeight uint, img image.Image) image.Image

Thumbnail will downscale provided image to max width and height preserving original aspect ratio and using the interpolation function interp. It will return original image, without processing it, if original sizes are already smaller than provided constraints.

Types

type Builtin

type Builtin struct{}

func (Builtin) EnableFlag

func (b Builtin) EnableFlag() string

func (Builtin) Generate

func (b Builtin) Generate(ctx context.Context, file io.Reader, src, name string, options map[string]string) (*Result, error)

func (Builtin) Priority

func (b Builtin) Priority() int

type FfmpegGenerator

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

func (*FfmpegGenerator) EnableFlag

func (f *FfmpegGenerator) EnableFlag() string

func (*FfmpegGenerator) Generate

func (f *FfmpegGenerator) Generate(ctx context.Context, file io.Reader, src, name string, options map[string]string) (*Result, error)

func (*FfmpegGenerator) Priority

func (f *FfmpegGenerator) Priority() int

type Generator

type Generator interface {
	// Generate generates a thumbnail for a given reader. Src is the original file path, only provided
	// for local policy files.
	Generate(ctx context.Context, file io.Reader, src string, name string, options map[string]string) (*Result, error)

	// Priority of execution order, smaller value means higher priority.
	Priority() int

	// EnableFlag returns the setting name to enable this generator.
	EnableFlag() string
}

Generator generates a thumbnail for a given reader.

type GeneratorList

type GeneratorList []Generator

func (GeneratorList) EnableFlag

func (p GeneratorList) EnableFlag() string

func (GeneratorList) Generate

func (p GeneratorList) Generate(ctx context.Context, file io.Reader, src, name string, options map[string]string) (*Result, error)

func (GeneratorList) Len

func (g GeneratorList) Len() int

func (GeneratorList) Less

func (g GeneratorList) Less(i, j int) bool

func (GeneratorList) Priority

func (p GeneratorList) Priority() int

func (GeneratorList) Swap

func (g GeneratorList) Swap(i, j int)

type GeneratorType

type GeneratorType string

type LibreOfficeGenerator

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

func (*LibreOfficeGenerator) EnableFlag

func (l *LibreOfficeGenerator) EnableFlag() string

func (*LibreOfficeGenerator) Generate

func (l *LibreOfficeGenerator) Generate(ctx context.Context, file io.Reader, src string, name string, options map[string]string) (*Result, error)

func (*LibreOfficeGenerator) Priority

func (l *LibreOfficeGenerator) Priority() int

type Result

type Result struct {
	Path     string
	Continue bool
	Cleanup  []func()
}

type Thumb

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

Thumb 缩略图

func NewThumbFromFile

func NewThumbFromFile(file io.Reader, name string) (*Thumb, error)

NewThumbFromFile 从文件数据获取新的Thumb对象, 尝试通过文件名name解码图像

func (*Thumb) CreateAvatar

func (image *Thumb) CreateAvatar(uid uint) error

CreateAvatar 创建头像

func (*Thumb) GetSize

func (image *Thumb) GetSize() (int, int)

GetSize 获取图像尺寸

func (*Thumb) GetThumb

func (image *Thumb) GetThumb(width, height uint)

GetThumb 生成给定最大尺寸的缩略图

func (*Thumb) Save

func (image *Thumb) Save(w io.Writer) (err error)

Save 保存图像到给定路径

type VipsGenerator

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

func (*VipsGenerator) EnableFlag

func (v *VipsGenerator) EnableFlag() string

func (*VipsGenerator) Generate

func (v *VipsGenerator) Generate(ctx context.Context, file io.Reader, src, name string, options map[string]string) (*Result, error)

func (*VipsGenerator) Priority

func (v *VipsGenerator) Priority() int

Jump to

Keyboard shortcuts

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