2020-05-05 15:42:54 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/thumb"
|
|
|
|
)
|
|
|
|
|
2020-07-14 14:30:19 +02:00
|
|
|
// JpegSize returns the size limit for automatically converted files in `PIXELS` (720-30000).
|
|
|
|
func (c *Config) JpegSize() int {
|
2020-12-18 20:42:12 +01:00
|
|
|
if c.options.JpegSize < 720 {
|
2020-07-13 15:23:54 +02:00
|
|
|
return 720
|
2020-12-18 20:42:12 +01:00
|
|
|
} else if c.options.JpegSize > 30000 {
|
2020-07-13 15:23:54 +02:00
|
|
|
return 30000
|
|
|
|
}
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.JpegSize
|
2020-07-13 15:23:54 +02:00
|
|
|
}
|
|
|
|
|
2022-04-01 13:25:25 +02:00
|
|
|
// JpegQuality returns the jpeg image quality as thumb.Quality (25-100).
|
|
|
|
func (c *Config) JpegQuality() thumb.Quality {
|
|
|
|
return thumb.ParseQuality(c.options.JpegQuality)
|
2020-05-05 15:42:54 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 17:17:19 +02:00
|
|
|
// ThumbFilter returns the thumbnail resample filter (best to worst: blackman, lanczos, cubic or linear).
|
|
|
|
func (c *Config) ThumbFilter() thumb.ResampleFilter {
|
2020-12-18 20:42:12 +01:00
|
|
|
switch strings.ToLower(c.options.ThumbFilter) {
|
2020-05-05 15:42:54 +02:00
|
|
|
case "blackman":
|
|
|
|
return thumb.ResampleBlackman
|
|
|
|
case "lanczos":
|
|
|
|
return thumb.ResampleLanczos
|
|
|
|
case "cubic":
|
|
|
|
return thumb.ResampleCubic
|
|
|
|
case "linear":
|
|
|
|
return thumb.ResampleLinear
|
|
|
|
default:
|
|
|
|
return thumb.ResampleCubic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 21:14:22 +02:00
|
|
|
// ThumbPath returns the thumbnail storage directory.
|
2020-05-05 17:04:13 +02:00
|
|
|
func (c *Config) ThumbPath() string {
|
|
|
|
return c.CachePath() + "/thumbnails"
|
|
|
|
}
|
|
|
|
|
2022-04-01 21:14:22 +02:00
|
|
|
// ThumbColorspace returns the standard colorspace for thumbnails.
|
|
|
|
func (c *Config) ThumbColorspace() string {
|
|
|
|
return c.options.ThumbColorspace
|
|
|
|
}
|
|
|
|
|
|
|
|
// ThumbStandardRGB checks if colors should be normalized to standard RGB in thumbnails.
|
|
|
|
func (c *Config) ThumbStandardRGB() bool {
|
|
|
|
return strings.ToLower(c.ThumbColorspace()) == "srgb"
|
|
|
|
}
|
|
|
|
|
2020-07-13 15:23:54 +02:00
|
|
|
// ThumbUncached checks if on-demand thumbnail rendering is enabled (high memory and cpu usage).
|
2020-05-05 17:04:13 +02:00
|
|
|
func (c *Config) ThumbUncached() bool {
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.ThumbUncached
|
2020-05-05 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
// ThumbSizePrecached returns the pre-cached thumbnail size limit in pixels (720-7680).
|
|
|
|
func (c *Config) ThumbSizePrecached() int {
|
2020-12-18 20:42:12 +01:00
|
|
|
size := c.options.ThumbSize
|
2020-05-05 17:04:13 +02:00
|
|
|
|
2020-07-13 15:23:54 +02:00
|
|
|
if size < 720 {
|
|
|
|
size = 720 // Mobile, TV
|
|
|
|
} else if size > 7680 {
|
|
|
|
size = 7680 // 8K Ultra HD
|
2020-05-05 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 15:23:54 +02:00
|
|
|
return size
|
2020-05-05 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 15:23:54 +02:00
|
|
|
// ThumbSizeUncached returns the on-demand rendering size limit in pixels (720-7680).
|
|
|
|
func (c *Config) ThumbSizeUncached() int {
|
2020-12-18 20:42:12 +01:00
|
|
|
limit := c.options.ThumbSizeUncached
|
2020-07-13 15:23:54 +02:00
|
|
|
|
|
|
|
if limit < 720 {
|
|
|
|
limit = 720 // Mobile, TV
|
|
|
|
} else if limit > 7680 {
|
|
|
|
limit = 7680 // 8K Ultra HD
|
|
|
|
}
|
|
|
|
|
2021-09-05 12:32:08 +02:00
|
|
|
if c.ThumbSizePrecached() > limit {
|
|
|
|
limit = c.ThumbSizePrecached()
|
2020-05-05 17:04:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 15:23:54 +02:00
|
|
|
return limit
|
2020-05-05 15:42:54 +02:00
|
|
|
}
|