mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:29:15 +00:00
Introduce thumbnail filtering options.
This commit is contained in:
@@ -17,9 +17,25 @@ import (
|
||||
"gopkg.in/vansante/go-ffprobe.v2"
|
||||
|
||||
_ "github.com/strukturag/libheif/go/heif"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func EncodeThumbnail(inputPath string, outputPath string) (*media_utils.PhotoDimensions, error) {
|
||||
var thumbFilter = map[int]imaging.ResampleFilter{
|
||||
0: imaging.NearestNeighbor,
|
||||
1: imaging.Box,
|
||||
2: imaging.Linear,
|
||||
3: imaging.MitchellNetravali,
|
||||
4: imaging.CatmullRom,
|
||||
5: imaging.Lanczos,
|
||||
}
|
||||
|
||||
func EncodeThumbnail(db *gorm.DB, inputPath string, outputPath string) (*media_utils.PhotoDimensions, error) {
|
||||
|
||||
var siteInfo models.SiteInfo
|
||||
if err := db.First(&siteInfo).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
inputImage, err := imaging.Open(inputPath, imaging.AutoOrientation(true))
|
||||
if err != nil {
|
||||
@@ -29,7 +45,7 @@ func EncodeThumbnail(inputPath string, outputPath string) (*media_utils.PhotoDim
|
||||
dimensions := media_utils.PhotoDimensionsFromRect(inputImage.Bounds())
|
||||
dimensions = dimensions.ThumbnailScale()
|
||||
|
||||
thumbImage := imaging.Resize(inputImage, dimensions.Width, dimensions.Height, imaging.NearestNeighbor)
|
||||
thumbImage := imaging.Resize(inputImage, dimensions.Width, dimensions.Height, thumbFilter[siteInfo.ThumbnailMethod])
|
||||
if err = encodeImageJPEG(thumbImage, outputPath, 60); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (t ProcessPhotoTask) ProcessMedia(ctx scanner_task.TaskContext, mediaData *
|
||||
updatedURLs = append(updatedURLs, thumbURL)
|
||||
fmt.Printf("Thumbnail photo found in database but not in cache, re-encoding photo to cache: %s\n", thumbURL.MediaName)
|
||||
|
||||
_, err := media_encoding.EncodeThumbnail(baseImagePath, thumbPath)
|
||||
_, err := media_encoding.EncodeThumbnail(ctx.GetDB(), baseImagePath, thumbPath)
|
||||
if err != nil {
|
||||
return []*models.MediaURL{}, errors.Wrap(err, "could not create thumbnail cached image")
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func generateSaveHighResJPEG(tx *gorm.DB, media *models.Media, imageData *media_
|
||||
func generateSaveThumbnailJPEG(tx *gorm.DB, media *models.Media, thumbnail_name string, photoCachePath string, baseImagePath string, mediaURL *models.MediaURL) (*models.MediaURL, error) {
|
||||
thumbOutputPath := path.Join(photoCachePath, thumbnail_name)
|
||||
|
||||
thumbSize, err := media_encoding.EncodeThumbnail(baseImagePath, thumbOutputPath)
|
||||
thumbSize, err := media_encoding.EncodeThumbnail(tx, baseImagePath, thumbOutputPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not create thumbnail cached image")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user