photoprism/internal/thumb/report.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

39 lines
929 B
Go

package thumb
import (
"fmt"
"sort"
"github.com/photoprism/photoprism/pkg/report"
)
// Report returns a file format documentation table.
func Report(sizes SizeList, short bool) (rows [][]string, cols []string) {
if short {
cols = []string{"Size", "Usage"}
} else {
cols = []string{"Name", "Width", "Height", "Aspect Ratio", "Usage"}
}
sorted := append(SizeList{}, sizes...)
sort.Slice(sorted, func(i, j int) bool {
if sorted[i].Width == sorted[j].Width {
return sorted[i].Name < sorted[j].Name
} else {
return sorted[i].Width < sorted[j].Width
}
})
rows = make([][]string, 0, len(sorted))
for _, s := range sorted {
if short {
rows = append(rows, []string{fmt.Sprintf("%d", s.Width), s.Usage})
} else {
rows = append(rows, []string{s.Name.String(), fmt.Sprintf("%d", s.Width), fmt.Sprintf("%d", s.Height), report.Bool(s.Fit, "Preserved", "1:1"), s.Usage})
}
}
return rows, cols
}