aboutsummaryrefslogtreecommitdiff
path: root/internal/thumbnail/save.go
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-13 14:44:12 +0530
committerGitHub <noreply@github.com>2026-07-13 14:44:12 +0530
commitcc639337ed5ccb4634b2a338f764cf9c73b02e4f (patch)
treeeae608923098a07f1413988cf0c79fc8ce4211be /internal/thumbnail/save.go
parented70370d9f58d39c3b31f5506e449aeb5d562a77 (diff)
parentc2e38ad8c3cff2d3c6ea627855b2b4f02dc3e9ba (diff)
downloadgalleryd-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/save.go')
-rw-r--r--internal/thumbnail/save.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/thumbnail/save.go b/internal/thumbnail/save.go
new file mode 100644
index 0000000..dba6dfa
--- /dev/null
+++ b/internal/thumbnail/save.go
@@ -0,0 +1,36 @@
+package thumbnail
+
+import (
+ "fmt"
+ "image"
+ "os"
+ "path/filepath"
+
+ "github.com/chai2010/webp"
+)
+
+// saveImage writes a thumbnail image to disk as WebP.
+func saveImage(path string, img image.Image) error {
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ return fmt.Errorf("created cache directory: %w", err)
+ }
+
+ file, err := os.Create(path)
+ if err != nil {
+ return fmt.Errorf("create thumbnail: %w", err)
+ }
+ defer func() {
+ _ = file.Close()
+ }()
+
+ options := &webp.Options{
+ Lossless: false,
+ Quality: 80,
+ }
+
+ if err := webp.Encode(file, img, options); err != nil {
+ return fmt.Errorf("encode webp: %w", err)
+ }
+
+ return nil
+}