mirror of
https://github.com/stashapp/stash.git
synced 2026-05-08 12:32:29 +02:00
generate sprite images in grid to fix tagger sprite view
This commit is contained in:
parent
f2e8bab58a
commit
25c5fb20fc
2 changed files with 26 additions and 8 deletions
|
|
@ -66,12 +66,17 @@ func (g Generator) CombineSpriteImages(images []image.Image) image.Image {
|
||||||
// Combine all of the thumbnails into a sprite image
|
// Combine all of the thumbnails into a sprite image
|
||||||
width := images[0].Bounds().Size().X
|
width := images[0].Bounds().Size().X
|
||||||
height := images[0].Bounds().Size().Y
|
height := images[0].Bounds().Size().Y
|
||||||
canvasWidth := width * len(images)
|
gridSize := utils.GetGridSizeFromImageCount(len(images))
|
||||||
canvasHeight := height
|
canvasWidth := width * gridSize
|
||||||
|
canvasHeight := height * gridSize
|
||||||
montage := imaging.New(canvasWidth, canvasHeight, color.NRGBA{})
|
montage := imaging.New(canvasWidth, canvasHeight, color.NRGBA{})
|
||||||
|
row := 0
|
||||||
for index := 0; index < len(images); index++ {
|
for index := 0; index < len(images); index++ {
|
||||||
x := width * index
|
if (index > 0) && (index%gridSize == 0) {
|
||||||
y := 0
|
row++
|
||||||
|
}
|
||||||
|
x := width * (index % gridSize)
|
||||||
|
y := height * row
|
||||||
img := images[index]
|
img := images[index]
|
||||||
montage = imaging.Paste(montage, img, image.Pt(x, y))
|
montage = imaging.Paste(montage, img, image.Pt(x, y))
|
||||||
}
|
}
|
||||||
|
|
@ -97,13 +102,19 @@ func (g Generator) spriteVTT(spritePath string, stepSize float64, video_duration
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
width := image.Width / number_of_sprites
|
|
||||||
height := image.Height
|
gridSize := utils.GetGridSizeFromImageCount(number_of_sprites)
|
||||||
|
width := image.Width / gridSize
|
||||||
|
height := image.Height / gridSize
|
||||||
|
|
||||||
vttLines := []string{"WEBVTT", ""}
|
vttLines := []string{"WEBVTT", ""}
|
||||||
|
row := 0
|
||||||
for index := 0; index < number_of_sprites; index++ {
|
for index := 0; index < number_of_sprites; index++ {
|
||||||
x := width * index
|
if (index > 0) && (index%gridSize == 0) {
|
||||||
y := 0
|
row++
|
||||||
|
}
|
||||||
|
x := width * (index % gridSize)
|
||||||
|
y := height * row
|
||||||
startTime := float64(index) * stepSize
|
startTime := float64(index) * stepSize
|
||||||
endTime := float64(index+1) * stepSize
|
endTime := float64(index+1) * stepSize
|
||||||
if endTime > video_duration {
|
if endTime > video_duration {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -120,3 +121,9 @@ func ServeImage(w http.ResponseWriter, r *http.Request, image []byte) {
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
ServeStaticContent(w, r, image)
|
ServeStaticContent(w, r, image)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGridSizeFromImageCount return the required size of a grid, where the number of images in width
|
||||||
|
// equals the number of images in height, to hold 'imageCount' images
|
||||||
|
func GetGridSizeFromImageCount(imageCount int) int {
|
||||||
|
return int(math.Ceil(math.Sqrt(float64(imageCount))))
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue