diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-07-13 14:44:12 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-13 14:44:12 +0530 |
| commit | cc639337ed5ccb4634b2a338f764cf9c73b02e4f (patch) | |
| tree | eae608923098a07f1413988cf0c79fc8ce4211be /internal/thumbnail/image.go | |
| parent | ed70370d9f58d39c3b31f5506e449aeb5d562a77 (diff) | |
| parent | c2e38ad8c3cff2d3c6ea627855b2b4f02dc3e9ba (diff) | |
| download | galleryd-cc639337ed5ccb4634b2a338f764cf9c73b02e4f.tar.xz galleryd-cc639337ed5ccb4634b2a338f764cf9c73b02e4f.zip | |
Merge pull request #5 from RanXom/feat/thumbnail
Feat/thumbnail: implement thumbnail generation and caching
Diffstat (limited to 'internal/thumbnail/image.go')
| -rw-r--r-- | internal/thumbnail/image.go | 30 |
1 files changed, 30 insertions, 0 deletions
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 +} |