2020-01-06 14:32:15 +01:00
|
|
|
package thumb
|
|
|
|
|
|
|
|
var (
|
2022-04-01 13:25:25 +02:00
|
|
|
SizePrecached = 2048
|
|
|
|
SizeUncached = 7680
|
|
|
|
Filter = ResampleLanczos
|
2020-01-06 14:32:15 +01:00
|
|
|
)
|
|
|
|
|
2020-05-05 15:42:54 +02:00
|
|
|
func MaxSize() int {
|
2021-09-05 12:32:08 +02:00
|
|
|
if SizePrecached > SizeUncached {
|
|
|
|
return SizePrecached
|
2020-05-05 15:42:54 +02:00
|
|
|
}
|
|
|
|
|
2020-07-18 17:33:02 +02:00
|
|
|
return SizeUncached
|
2020-05-05 15:42:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func InvalidSize(size int) bool {
|
|
|
|
return size < 0 || size > MaxSize()
|
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
type Size struct {
|
2021-09-05 17:10:52 +02:00
|
|
|
Name Name `json:"name"`
|
2021-09-05 13:48:53 +02:00
|
|
|
Source Name `json:"-"`
|
2021-09-05 17:10:52 +02:00
|
|
|
Use string `json:"use"`
|
2020-07-13 15:23:54 +02:00
|
|
|
Width int `json:"w"`
|
|
|
|
Height int `json:"h"`
|
|
|
|
Public bool `json:"-"`
|
|
|
|
Options []ResampleOption `json:"-"`
|
2020-01-06 14:32:15 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
type SizeMap map[Name]Size
|
2020-05-13 15:36:42 +02:00
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
// Sizes contains the properties of all thumbnail sizes.
|
2021-09-05 12:32:08 +02:00
|
|
|
var Sizes = SizeMap{
|
2021-09-05 17:10:52 +02:00
|
|
|
Tile50: {Tile50, Tile500, "Lists", 50, 50, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
Tile100: {Tile100, Tile500, "Maps", 100, 100, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
Tile224: {Tile224, Tile500, "TensorFlow, Mosaic", 224, 224, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
Tile500: {Tile500, "", "Tiles", 500, 500, false, []ResampleOption{ResampleFillCenter, ResampleDefault}},
|
|
|
|
Colors: {Colors, Fit720, "Color Detection", 3, 3, false, []ResampleOption{ResampleResize, ResampleNearestNeighbor, ResamplePng}},
|
|
|
|
Left224: {Left224, Fit720, "TensorFlow", 224, 224, false, []ResampleOption{ResampleFillTopLeft, ResampleDefault}},
|
|
|
|
Right224: {Right224, Fit720, "TensorFlow", 224, 224, false, []ResampleOption{ResampleFillBottomRight, ResampleDefault}},
|
|
|
|
Fit720: {Fit720, "", "Mobile, TV", 720, 720, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit1280: {Fit1280, Fit2048, "Mobile, HD Ready TV", 1280, 1024, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit1920: {Fit1920, Fit2048, "Mobile, Full HD TV", 1920, 1200, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit2048: {Fit2048, "", "Tablets, Cinema 2K", 2048, 2048, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit2560: {Fit2560, "", "Quad HD, Retina Display", 2560, 1600, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit3840: {Fit3840, "", "Ultra HD", 3840, 2400, false, []ResampleOption{ResampleFit, ResampleDefault}}, // Deprecated in favor of fit_4096
|
|
|
|
Fit4096: {Fit4096, "", "Ultra HD, Retina 4K", 4096, 4096, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
|
|
|
Fit7680: {Fit7680, "", "8K Ultra HD 2, Retina 6K", 7680, 4320, true, []ResampleOption{ResampleFit, ResampleDefault}},
|
2020-01-06 14:32:15 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 13:48:53 +02:00
|
|
|
// DefaultSizes contains all default size names.
|
|
|
|
var DefaultSizes = []Name{
|
|
|
|
Fit7680,
|
|
|
|
Fit4096,
|
|
|
|
Fit2560,
|
|
|
|
Fit2048,
|
|
|
|
Fit1920,
|
|
|
|
Fit1280,
|
|
|
|
Fit720,
|
|
|
|
Right224,
|
|
|
|
Left224,
|
|
|
|
Colors,
|
|
|
|
Tile500,
|
|
|
|
Tile224,
|
|
|
|
Tile100,
|
|
|
|
Tile50,
|
2020-01-06 14:32:15 +01:00
|
|
|
}
|
2020-01-13 11:07:09 +01:00
|
|
|
|
2020-07-18 17:33:02 +02:00
|
|
|
// Find returns the largest default thumbnail type for the given size limit.
|
2021-09-05 13:48:53 +02:00
|
|
|
func Find(limit int) (name Name, size Size) {
|
2021-09-05 12:32:08 +02:00
|
|
|
for _, name = range DefaultSizes {
|
|
|
|
t := Sizes[name]
|
2020-07-18 17:33:02 +02:00
|
|
|
|
|
|
|
if t.Width <= limit && t.Height <= limit {
|
|
|
|
return name, t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
return "", Size{}
|
2020-07-18 17:33:02 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
// Uncached tests if thumbnail type exceeds the cached thumbnails size limit.
|
|
|
|
func (s Size) Uncached() bool {
|
|
|
|
return s.Width > SizePrecached || s.Height > SizePrecached
|
2020-01-13 11:07:09 +01:00
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
// ExceedsLimit tests if thumbnail type is too large, and can not be rendered at all.
|
|
|
|
func (s Size) ExceedsLimit() bool {
|
|
|
|
return s.Width > MaxSize() || s.Height > MaxSize()
|
2020-01-13 11:07:09 +01:00
|
|
|
}
|