diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-13 13:12:25 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-13 13:12:25 +0530 |
| commit | 12226cf4b6b6b050a12ceb7c47f1b67c0cd16b78 (patch) | |
| tree | 416c07b9b5d4c96bd24dd9683837f35d00071385 /internal | |
| parent | 8fd991a5a618e4dd0086669d682ead22d99a3a6e (diff) | |
| download | galleryd-12226cf4b6b6b050a12ceb7c47f1b67c0cd16b78.tar.xz galleryd-12226cf4b6b6b050a12ceb7c47f1b67c0cd16b78.zip | |
feat(thumbnail): generate thumbnail images
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/thumbnail/generator.go | 5 | ||||
| -rw-r--r-- | internal/thumbnail/image.go | 30 |
2 files changed, 35 insertions, 0 deletions
diff --git a/internal/thumbnail/generator.go b/internal/thumbnail/generator.go index c35db08..226fc0e 100644 --- a/internal/thumbnail/generator.go +++ b/internal/thumbnail/generator.go @@ -22,6 +22,11 @@ func (g *Generator) Generate( ctx context.Context, photo gallery.Photo, ) (Thumbnail, error) { + _, err := generateImage(photo) + if err != nil { + return Thumbnail{}, err + } + return Thumbnail{ Path: g.cachePath(photo), }, nil diff --git a/internal/thumbnail/image.go b/internal/thumbnail/image.go new file mode 100644 index 0000000..d844d53 --- /dev/null +++ b/internal/thumbnail/image.go @@ -0,0 +1,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 +} |