photoprism/internal/thumb/resample_options.go
Michael Mayer 68ba289d6c CLI: Add "photoprism show config/formats" subcommands
Replaces "photoprism config", which could only display
current configuration values. Codecs and file formats
have been refactored along the way.

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2022-04-12 13:28:28 +02:00

57 lines
1.3 KiB
Go

package thumb
import (
"github.com/disintegration/imaging"
"github.com/photoprism/photoprism/pkg/fs"
)
type ResampleOption int
const (
ResampleFillCenter ResampleOption = iota
ResampleFillTopLeft
ResampleFillBottomRight
ResampleFit
ResampleResize
ResampleNearestNeighbor
ResampleDefault
ResamplePng
)
var ResampleMethods = map[ResampleOption]string{
ResampleFillCenter: "center",
ResampleFillTopLeft: "left",
ResampleFillBottomRight: "right",
ResampleFit: "fit",
ResampleResize: "resize",
}
// ResampleOptions extracts filter, format, and method from resample options.
func ResampleOptions(opts ...ResampleOption) (method ResampleOption, filter imaging.ResampleFilter, format fs.Format) {
method = ResampleFit
filter = imaging.Lanczos
format = fs.FormatJpeg
for _, option := range opts {
switch option {
case ResamplePng:
format = fs.FormatPng
case ResampleNearestNeighbor:
filter = imaging.NearestNeighbor
case ResampleDefault:
filter = Filter.Imaging()
case ResampleFillTopLeft:
method = ResampleFillTopLeft
case ResampleFillCenter:
method = ResampleFillCenter
case ResampleFillBottomRight:
method = ResampleFillBottomRight
case ResampleFit:
method = ResampleFit
case ResampleResize:
method = ResampleResize
}
}
return method, filter, format
}