2021-09-05 13:48:53 +02:00
|
|
|
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.
|
2022-04-15 09:42:07 +02:00
|
|
|
func ResampleOptions(opts ...ResampleOption) (method ResampleOption, filter imaging.ResampleFilter, format fs.Type) {
|
2021-09-05 13:48:53 +02:00
|
|
|
method = ResampleFit
|
|
|
|
filter = imaging.Lanczos
|
2022-04-15 09:42:07 +02:00
|
|
|
format = fs.ImageJPEG
|
2021-09-05 13:48:53 +02:00
|
|
|
|
|
|
|
for _, option := range opts {
|
|
|
|
switch option {
|
|
|
|
case ResamplePng:
|
2022-04-15 09:42:07 +02:00
|
|
|
format = fs.ImagePNG
|
2021-09-05 13:48:53 +02:00
|
|
|
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
|
|
|
|
}
|