mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 05:01:10 -05:00
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
//go:build !enable_vips
|
|
|
|
package thumbnail
|
|
|
|
import (
|
|
"image"
|
|
|
|
"github.com/kovidgoyal/imaging"
|
|
"github.com/opencloud-eu/opencloud/services/thumbnails/pkg/errors"
|
|
)
|
|
|
|
// SimpleGenerator is the default image generator and is used for all image types expect gif.
|
|
type SimpleGenerator struct {
|
|
processor Processor
|
|
}
|
|
|
|
func NewSimpleGenerator(filetype, process string) (SimpleGenerator, error) {
|
|
processor, err := ProcessorFor(process, filetype)
|
|
if err != nil {
|
|
return SimpleGenerator{}, err
|
|
}
|
|
return SimpleGenerator{processor: processor}, nil
|
|
}
|
|
|
|
// ProcessorID returns the processor identification.
|
|
func (g SimpleGenerator) ProcessorID() string {
|
|
return g.processor.ID()
|
|
}
|
|
|
|
// Generate generates a alternative image version.
|
|
func (g SimpleGenerator) Generate(size image.Rectangle, img interface{}) (interface{}, error) {
|
|
m, ok := img.(image.Image)
|
|
if !ok {
|
|
return nil, errors.ErrInvalidType
|
|
}
|
|
|
|
return g.processor.Process(m, size.Dx(), size.Dy(), imaging.Lanczos), nil
|
|
}
|
|
|
|
func (g SimpleGenerator) Dimensions(img interface{}) (image.Rectangle, error) {
|
|
m, ok := img.(image.Image)
|
|
if !ok {
|
|
return image.Rectangle{}, errors.ErrInvalidType
|
|
}
|
|
return m.Bounds(), nil
|
|
}
|