photoprism/internal/thumb/fit.go
Michael Mayer 3cf1c699df Video: Refactor FFmpeg Transcoding Size Limit #3466 #3498 #3549
Signed-off-by: Michael Mayer <michael@photoprism.app>
2023-07-18 15:15:04 +02:00

34 lines
738 B
Go

package thumb
import "image"
// FitSizes contains "fit" cropped thumbnail sizes from largest to smallest.
// Best for the viewer as proportional resizing maintains the aspect ratio.
var FitSizes = SizeList{
Sizes[Fit7680],
Sizes[Fit4096],
Sizes[Fit3840],
Sizes[Fit2560],
Sizes[Fit2048],
Sizes[Fit1920],
Sizes[Fit1280],
Sizes[Fit720],
}
// Fit returns the largest fitting thumbnail size.
func Fit(w, h int) (size Size) {
j := len(FitSizes) - 1
for i := j; i >= 0; i-- {
if size = FitSizes[i]; w <= size.Width && h <= size.Height {
return size
}
}
return FitSizes[0]
}
// FitBounds returns the largest thumbnail size fitting the rectangle.
func FitBounds(r image.Rectangle) (s Size) {
return Fit(r.Dx(), r.Dy())
}