Skip to content
Snippets Groups Projects
Commit dabdaece authored by Travis Ralston's avatar Travis Ralston
Browse files

Add support for dynamic thumbnails

parent 26c5d380
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Add apng image support. Thanks @Sorunome!
* Experimental support for Redis as a cache (in preparation for proper load balancing/HA support).
* Added oEmbed URL preview support.
* Added support for dynamic thumbnails.
### Changed
......
......@@ -61,6 +61,7 @@ func NewDefaultDomainConfig() DomainRepoConfig {
{640, 480},
{800, 600},
},
DynamicSizing: false,
Types: []string{
"image/jpeg",
"image/jpg",
......
......@@ -96,6 +96,7 @@ func NewDefaultMainConfig() MainRepoConfig {
{640, 480},
{800, 600},
},
DynamicSizing: false,
Types: []string{
"image/jpeg",
"image/jpg",
......
......@@ -29,6 +29,7 @@ type ThumbnailsConfig struct {
Types []string `yaml:"types,flow"`
MaxAnimateSizeBytes int64 `yaml:"maxAnimateSizeBytes"`
Sizes []ThumbnailSize `yaml:"sizes,flow"`
DynamicSizing bool `yaml:"dynamicSizing"`
AllowAnimated bool `yaml:"allowAnimated"`
DefaultAnimated bool `yaml:"defaultAnimated"`
StillFrame float32 `yaml:"stillFrame"`
......
......@@ -350,6 +350,12 @@ thumbnails:
- width: 800
height: 600
# To allow for thumbnails to be any size, not just in the sizes specified above, set this to
# true (default false). When enabled, whatever size requested by the client will be generated
# up to a maximum of the largest possible dimensions in the `sizes` list. For best results,
# specify only one size in the `sizes` list when this option is enabled.
dynamicSizing: false
# The content types to thumbnail when requested. Types that are not supported by the media repo
# will not be thumbnailed (adding application/json here won't work). Clients may still not request
# thumbnails for these types - this won't make clients automatically thumbnail these file types.
......
......@@ -241,6 +241,10 @@ func pickThumbnailDimensions(desiredWidth int, desiredHeight int, desiredMethod
}
}
if ctx.Config.Thumbnails.DynamicSizing {
return util.MinInt(largestWidth, desiredWidth), util.MinInt(largestHeight, desiredHeight), desiredMethod, nil
}
// Use the largest dimensions available if we didn't find anything
if !foundSize {
targetWidth = largestWidth
......
......@@ -7,6 +7,13 @@ func MaxInt(a int, b int) int {
return b
}
func MinInt(a int, b int) int {
if a < b {
return a
}
return b
}
func MinFloat32(a float32, b float32) float32 {
if a < b {
return a
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment