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

@ -20,4 +20,4 @@ func (r *queryResolver) Logs(ctx context.Context) ([]*models.LogEntry, error) {
}
return ret, nil
}
}

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

@ -9,7 +9,7 @@ import (
)
var (
streamingFiles = make(map[string][]*http.ResponseWriter)
streamingFiles = make(map[string][]*http.ResponseWriter)
streamingFilesMutex = sync.RWMutex{}
)

View File

@ -6,16 +6,16 @@ import (
"strconv"
"github.com/jmoiron/sqlx"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/models"
"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()
_, err := qb.Find(sceneID)
if err != nil {
return err
@ -40,7 +40,7 @@ func DestroyScene(sceneID int, tx *sqlx.Tx) (error) {
if err := qb.Destroy(strconv.Itoa(sceneID), tx); err != nil {
return err
}
return nil
}
@ -130,4 +130,4 @@ func DeleteSceneFile(scene *models.Scene) {
if err != nil {
logger.Warnf("Could not delete file %s: %s", scene.Path, err.Error())
}
}
}

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 {

View File

@ -162,8 +162,8 @@ func (qb *SceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterTyp
havingClauses = append(havingClauses, "((COUNT(DISTINCT ptj.id) + COUNT(DISTINCT tj.tag_id)) >= "+strconv.Itoa(requiredCount)+")")
} else if tagsFilter.Modifier == CriterionModifierExcludes {
// excludes all of the provided ids
whereClauses = append(whereClauses, "scene_markers.primary_tag_id not in " + getInBinding(length))
whereClauses = append(whereClauses, "not exists (select smt.scene_marker_id from scene_markers_tags as smt where smt.scene_marker_id = scene_markers.id and smt.tag_id in " + getInBinding(length) + ")")
whereClauses = append(whereClauses, "scene_markers.primary_tag_id not in "+getInBinding(length))
whereClauses = append(whereClauses, "not exists (select smt.scene_marker_id from scene_markers_tags as smt where smt.scene_marker_id = scene_markers.id and smt.tag_id in "+getInBinding(length)+")")
}
for _, tagID := range tagsFilter.Value {
@ -176,7 +176,7 @@ func (qb *SceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterTyp
if sceneTagsFilter := sceneMarkerFilter.SceneTags; sceneTagsFilter != nil && len(sceneTagsFilter.Value) > 0 {
length := len(sceneTagsFilter.Value)
if sceneTagsFilter.Modifier == CriterionModifierIncludes || sceneTagsFilter.Modifier == CriterionModifierIncludesAll {
body += " LEFT JOIN scenes_tags AS scene_tags_join ON scene_tags_join.scene_id = scene.id AND scene_tags_join.tag_id IN " + getInBinding(length)
@ -191,9 +191,9 @@ func (qb *SceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterTyp
havingClauses = append(havingClauses, "COUNT(DISTINCT scene_tags_join.tag_id) >= "+strconv.Itoa(requiredCount))
} else if sceneTagsFilter.Modifier == CriterionModifierExcludes {
// excludes all of the provided ids
whereClauses = append(whereClauses, "not exists (select st.scene_id from scenes_tags as st where st.scene_id = scene.id AND st.tag_id IN " + getInBinding(length) + ")")
whereClauses = append(whereClauses, "not exists (select st.scene_id from scenes_tags as st where st.scene_id = scene.id AND st.tag_id IN "+getInBinding(length)+")")
}
for _, tagID := range sceneTagsFilter.Value {
args = append(args, tagID)
}
@ -213,13 +213,13 @@ func (qb *SceneMarkerQueryBuilder) Query(sceneMarkerFilter *SceneMarkerFilterTyp
if performersFilter.Modifier == CriterionModifierIncludesAll {
requiredCount = length
}
havingClauses = append(havingClauses, "COUNT(DISTINCT scene_performers.performer_id) >= "+strconv.Itoa(requiredCount))
} else if performersFilter.Modifier == CriterionModifierExcludes {
// excludes all of the provided ids
whereClauses = append(whereClauses, "not exists (select sp.scene_id from performers_scenes as sp where sp.scene_id = scene.id AND sp.performer_id IN " + getInBinding(length) + ")")
whereClauses = append(whereClauses, "not exists (select sp.scene_id from performers_scenes as sp where sp.scene_id = scene.id AND sp.performer_id IN "+getInBinding(length)+")")
}
for _, performerID := range performersFilter.Value {
args = append(args, performerID)
}

View File

@ -1,3 +1,3 @@
package utils
var PendingGenerateResource, _ = GetDataFromBase64String("iVBORw0KGgoAAAANSUhEUgAAAfQAAADwBAMAAAAEHosbAAAAG1BMVEUAA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