2020-01-06 14:32:15 +01:00
|
|
|
package thumb
|
|
|
|
|
2020-01-13 11:07:09 +01:00
|
|
|
import "github.com/disintegration/imaging"
|
|
|
|
|
2020-01-06 14:32:15 +01:00
|
|
|
var (
|
2020-01-13 11:07:09 +01:00
|
|
|
PreRenderSize = 3840
|
|
|
|
MaxRenderSize = 3840
|
2020-01-06 14:32:15 +01:00
|
|
|
JpegQuality = 95
|
|
|
|
JpegQualitySmall = 80
|
2020-01-13 13:46:05 +01:00
|
|
|
Filter = ResampleLanczos
|
2020-01-06 14:32:15 +01:00
|
|
|
)
|
|
|
|
|
2020-01-13 11:07:09 +01:00
|
|
|
const (
|
2020-01-13 13:46:05 +01:00
|
|
|
ResampleBlackman ResampleFilter = "blackman"
|
|
|
|
ResampleLanczos ResampleFilter = "lanczos"
|
|
|
|
ResampleCubic ResampleFilter = "cubic"
|
|
|
|
ResampleLinear ResampleFilter = "linear"
|
2020-01-13 11:07:09 +01:00
|
|
|
)
|
|
|
|
|
2020-01-13 13:46:05 +01:00
|
|
|
type ResampleFilter string
|
2020-01-13 11:07:09 +01:00
|
|
|
|
2020-01-13 13:46:05 +01:00
|
|
|
func (a ResampleFilter) Imaging() imaging.ResampleFilter {
|
2020-01-13 11:07:09 +01:00
|
|
|
switch a {
|
2020-01-13 12:25:16 +01:00
|
|
|
case ResampleBlackman:
|
|
|
|
return imaging.Blackman
|
2020-01-13 11:07:09 +01:00
|
|
|
case ResampleLanczos:
|
|
|
|
return imaging.Lanczos
|
|
|
|
case ResampleCubic:
|
|
|
|
return imaging.CatmullRom
|
|
|
|
case ResampleLinear:
|
|
|
|
return imaging.Linear
|
|
|
|
default:
|
|
|
|
return imaging.Lanczos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-06 14:32:15 +01:00
|
|
|
const (
|
|
|
|
ResampleFillCenter ResampleOption = iota
|
|
|
|
ResampleFillTopLeft
|
|
|
|
ResampleFillBottomRight
|
|
|
|
ResampleFit
|
|
|
|
ResampleResize
|
|
|
|
ResampleNearestNeighbor
|
2020-01-13 11:07:09 +01:00
|
|
|
ResampleDefault
|
2020-01-06 14:32:15 +01:00
|
|
|
ResamplePng
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResampleOption int
|
|
|
|
|
|
|
|
var ResampleMethods = map[ResampleOption]string{
|
|
|
|
ResampleFillCenter: "center",
|
|
|
|
ResampleFillTopLeft: "left",
|
|
|
|
ResampleFillBottomRight: "right",
|
|
|
|
ResampleFit: "fit",
|
|
|
|
ResampleResize: "resize",
|
|
|
|
}
|
|
|
|
|
|
|
|
type Type struct {
|
|
|
|
Source string
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
Public bool
|
|
|
|
Options []ResampleOption
|
|
|
|
}
|
|
|
|
|
|
|
|
var Types = map[string]Type{
|
2020-01-13 11:07:09 +01:00
|
|
|
"tile_50": {"tile_500", 50, 50, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
"tile_100": {"tile_500", 100, 100, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
"tile_224": {"tile_500", 224, 224, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
"tile_500": {"", 500, 500, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
2020-01-06 14:32:15 +01:00
|
|
|
"colors": {"fit_720", 3, 3, false, []ResampleOption{ResampleResize, ResampleNearestNeighbor, ResamplePng}},
|
2020-01-13 11:07:09 +01:00
|
|
|
"left_224": {"fit_720", 224, 224, false, []ResampleOption{ResampleFillTopLeft, ResampleDefault}},
|
|
|
|
"right_224": {"fit_720", 224, 224, false, []ResampleOption{ResampleFillBottomRight, ResampleDefault}},
|
|
|
|
"fit_720": {"", 720, 720, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
"fit_1280": {"fit_2048", 1280, 1024, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
"fit_1920": {"fit_2048", 1920, 1200, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
"fit_2048": {"", 2048, 2048, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
"fit_2560": {"", 2560, 1600, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
"fit_3840": {"", 3840, 2400, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
2020-01-06 14:32:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var DefaultTypes = []string{
|
|
|
|
"fit_3840", "fit_2560", "fit_2048", "fit_1920", "fit_1280", "fit_720", "right_224", "left_224", "colors", "tile_500", "tile_224", "tile_100", "tile_50",
|
|
|
|
}
|
2020-01-13 11:07:09 +01:00
|
|
|
|
|
|
|
func (t Type) ExceedsLimit() bool {
|
|
|
|
return t.Width > MaxRenderSize || t.Height > MaxRenderSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Type) SkipPreRender() bool {
|
|
|
|
return t.Width > PreRenderSize || t.Height > PreRenderSize
|
|
|
|
}
|