aboutsummaryrefslogtreecommitdiff
path: root/internal/thumbnail/image.go
blob: d844d53b044926e12df85c24a8d4283cabe1fe92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package thumbnail

import (
	"fmt"
	"image"

	"github.com/RanXom/galleryd/internal/gallery"
	"github.com/disintegration/imaging"
)

const thumbnailSize = 512

// generateImage decodes and resizes a photo.
//
// The returned image is not written to disk.
func generateImage(photo gallery.Photo) (image.Image, error) {
	src, err := imaging.Open(photo.Path)
	if err != nil {
		return nil, fmt.Errorf("open image: %w", err)
	}

	thumb := imaging.Fit(
		src,
		thumbnailSize,
		thumbnailSize,
		imaging.Lanczos,
	)

	return thumb, nil
}