Search: Add filter to find pictures by resolution range in MP #3896
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
717e616700
commit
eb19a4a893
4 changed files with 41 additions and 28 deletions
|
@ -32,6 +32,7 @@ type SearchPhotos struct {
|
|||
Raw bool `form:"raw" notes:"Finds pictures with RAW image file"`
|
||||
Live bool `form:"live" notes:"Finds Live Photos and short videos"`
|
||||
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
|
||||
Mp string `form:"mp" example:"mp:3-6" notes:"Resolution in Megapixels (MP)"`
|
||||
Panorama bool `form:"panorama" notes:"Finds pictures with an aspect ratio > 1.9:1"`
|
||||
Portrait bool `form:"portrait" notes:"Finds pictures in portrait format"`
|
||||
Landscape bool `form:"landscape" notes:"Finds pictures in landscape format"`
|
||||
|
|
|
@ -29,6 +29,7 @@ type SearchPhotosGeo struct {
|
|||
Raw bool `form:"raw"`
|
||||
Live bool `form:"live"`
|
||||
Scan string `form:"scan" example:"scan:true scan:false" notes:"Finds scanned photos and documents"`
|
||||
Mp string `form:"mp" example:"mp:3-6" notes:"Resolution in Megapixels (MP)"`
|
||||
Panorama bool `form:"panorama"`
|
||||
Portrait bool `form:"portrait"`
|
||||
Landscape bool `form:"landscape"`
|
||||
|
|
|
@ -524,6 +524,25 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
|
|||
s = s.Where(AnyInt("photos.photo_day", f.Day, txt.Or, entity.UnknownDay, txt.DayMax))
|
||||
}
|
||||
|
||||
// Filter by Resolution in Megapixels (MP).
|
||||
if rangeStart, rangeEnd, rangeErr := txt.IntRange(f.Mp, 0, 32000); rangeErr == nil {
|
||||
s = s.Where("photos.photo_resolution >= ? AND photos.photo_resolution <= ?", rangeStart, rangeEnd)
|
||||
}
|
||||
|
||||
// Find panoramic pictures only.
|
||||
if f.Panorama {
|
||||
s = s.Where("photos.photo_panorama = 1")
|
||||
}
|
||||
|
||||
// Find portrait/landscape/square pictures only.
|
||||
if f.Portrait {
|
||||
s = s.Where("files.file_portrait = 1")
|
||||
} else if f.Landscape {
|
||||
s = s.Where("files.file_aspect_ratio > 1.25")
|
||||
} else if f.Square {
|
||||
s = s.Where("files.file_aspect_ratio = 1")
|
||||
}
|
||||
|
||||
// Filter by main color.
|
||||
if f.Color != "" {
|
||||
s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color)))
|
||||
|
@ -556,20 +575,7 @@ func searchPhotos(f form.SearchPhotos, sess *entity.Session, resultCols string)
|
|||
s = s.Where("photos.photo_scan = 1")
|
||||
}
|
||||
|
||||
// Find panoramas only.
|
||||
if f.Panorama {
|
||||
s = s.Where("photos.photo_panorama = 1")
|
||||
}
|
||||
|
||||
// Find portrait/landscape/square pictures only.
|
||||
if f.Portrait {
|
||||
s = s.Where("files.file_portrait = 1")
|
||||
} else if f.Landscape {
|
||||
s = s.Where("files.file_aspect_ratio > 1.25")
|
||||
} else if f.Square {
|
||||
s = s.Where("files.file_aspect_ratio = 1")
|
||||
}
|
||||
|
||||
// Filter by stack flag.
|
||||
if f.Stackable {
|
||||
s = s.Where("photos.photo_stack > -1")
|
||||
} else if f.Unstacked {
|
||||
|
|
|
@ -437,6 +437,25 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
|
|||
s = s.Where(AnyInt("photos.photo_day", f.Day, txt.Or, entity.UnknownDay, txt.DayMax))
|
||||
}
|
||||
|
||||
// Filter by Resolution in Megapixels (MP).
|
||||
if rangeStart, rangeEnd, rangeErr := txt.IntRange(f.Mp, 0, 32000); rangeErr == nil {
|
||||
s = s.Where("photos.photo_resolution >= ? AND photos.photo_resolution <= ?", rangeStart, rangeEnd)
|
||||
}
|
||||
|
||||
// Find panoramic pictures only.
|
||||
if f.Panorama {
|
||||
s = s.Where("photos.photo_panorama = 1")
|
||||
}
|
||||
|
||||
// Find portrait/landscape/square pictures only.
|
||||
if f.Portrait {
|
||||
s = s.Where("files.file_portrait = 1")
|
||||
} else if f.Landscape {
|
||||
s = s.Where("files.file_aspect_ratio > 1.25")
|
||||
} else if f.Square {
|
||||
s = s.Where("files.file_aspect_ratio = 1")
|
||||
}
|
||||
|
||||
// Filter by main color.
|
||||
if f.Color != "" {
|
||||
s = s.Where("files.file_main_color IN (?)", SplitOr(strings.ToLower(f.Color)))
|
||||
|
@ -465,20 +484,6 @@ func UserPhotosGeo(f form.SearchPhotosGeo, sess *entity.Session) (results GeoRes
|
|||
s = s.Where("photos.photo_scan = 1")
|
||||
}
|
||||
|
||||
// Find panoramas only.
|
||||
if f.Panorama {
|
||||
s = s.Where("photos.photo_panorama = 1")
|
||||
}
|
||||
|
||||
// Find portrait/landscape/square pictures only.
|
||||
if f.Portrait {
|
||||
s = s.Where("files.file_portrait = 1")
|
||||
} else if f.Landscape {
|
||||
s = s.Where("files.file_aspect_ratio > 1.25")
|
||||
} else if f.Square {
|
||||
s = s.Where("files.file_aspect_ratio = 1")
|
||||
}
|
||||
|
||||
// Filter by location country.
|
||||
if f.Country != "" {
|
||||
s = s.Where("photos.photo_country IN (?)", SplitOr(strings.ToLower(f.Country)))
|
||||
|
|
Loading…
Add table
Reference in a new issue