Change thumbnail default size and resize algorithm (#336)

* Change thumbnail resize algorithm and add size parameter

* Height -> Width

* Change default size from 100px to 200px

* Height -> width
This commit is contained in:
InfiniteTF
2020-01-31 23:19:15 +01:00
committed by GitHub
parent 03c07a429d
commit 6a6e8d8875
10 changed files with 30 additions and 21 deletions

View File

@@ -27,9 +27,16 @@ func (rs galleryRoutes) File(w http.ResponseWriter, r *http.Request) {
thumb := r.URL.Query().Get("thumb") thumb := r.URL.Query().Get("thumb")
w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week
if thumb == "true" { if thumb == "true" {
_, _ = w.Write(gallery.GetThumbnail(fileIndex)) _, _ = w.Write(gallery.GetThumbnail(fileIndex, 200))
} else { } else if thumb == "" {
_, _ = w.Write(gallery.GetImage(fileIndex)) _, _ = w.Write(gallery.GetImage(fileIndex))
} else {
width, err := strconv.ParseInt(thumb, 0, 64)
if err != nil {
http.Error(w, http.StatusText(400), 400)
return
}
_, _ = w.Write(gallery.GetThumbnail(fileIndex, int(width)))
} }
} }

View File

@@ -28,6 +28,7 @@ var once sync.Once
type flagStruct struct { type flagStruct struct {
configFilePath string configFilePath string
} }
var flags = flagStruct{} var flags = flagStruct{}
func GetInstance() *singleton { func GetInstance() *singleton {

View File

@@ -12,7 +12,7 @@ import (
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
) )
func DestroyScene(sceneID int, tx *sqlx.Tx) (error) { func DestroyScene(sceneID int, tx *sqlx.Tx) error {
qb := models.NewSceneQueryBuilder() qb := models.NewSceneQueryBuilder()
jqb := models.NewJoinsQueryBuilder() jqb := models.NewJoinsQueryBuilder()

View File

@@ -26,6 +26,7 @@ const testExtension = ".mp4"
const existingStudioName = "ExistingStudio" const existingStudioName = "ExistingStudio"
const existingStudioSceneName = testName + ".dontChangeStudio" + testExtension const existingStudioSceneName = testName + ".dontChangeStudio" + testExtension
var existingStudioID int var existingStudioID int
var testSeparators = []string{ var testSeparators = []string{

View File

@@ -52,13 +52,13 @@ func (g *Gallery) GetImage(index int) []byte {
return data return data
} }
func (g *Gallery) GetThumbnail(index int) []byte { func (g *Gallery) GetThumbnail(index int, width int) []byte {
data, _ := g.readZipFile(index) data, _ := g.readZipFile(index)
srcImage, _, err := image.Decode(bytes.NewReader(data)) srcImage, _, err := image.Decode(bytes.NewReader(data))
if err != nil { if err != nil {
return data return data
} }
resizedImage := imaging.Resize(srcImage, 100, 0, imaging.NearestNeighbor) resizedImage := imaging.Resize(srcImage, width, 0, imaging.Box)
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
err = jpeg.Encode(buf, resizedImage, nil) err = jpeg.Encode(buf, resizedImage, nil)
if err != nil { if err != nil {