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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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")
w.Header().Add("Cache-Control", "max-age=604800000") // 1 Week
if thumb == "true" {
_, _ = w.Write(gallery.GetThumbnail(fileIndex))
} else {
_, _ = w.Write(gallery.GetThumbnail(fileIndex, 200))
} else if thumb == "" {
_, _ = 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 {
configFilePath string
}
var flags = flagStruct{}
func GetInstance() *singleton {

View file

@ -12,7 +12,7 @@ import (
"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()
jqb := models.NewJoinsQueryBuilder()

View file

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

View file

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