aboutsummaryrefslogtreecommitdiff
path: root/internal/metadata/dimensions.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 02:46:31 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 02:46:31 +0530
commit00c0080ff66ac0e722f7213ccc8f3dd28a0f2e8f (patch)
treebb6e30ad3964433bcc551e1918ee0eb3c97d9d43 /internal/metadata/dimensions.go
parent07edb835b5f217bf90d3453c0a210790fab4a6cb (diff)
downloadgalleryd-00c0080ff66ac0e722f7213ccc8f3dd28a0f2e8f.tar.xz
galleryd-00c0080ff66ac0e722f7213ccc8f3dd28a0f2e8f.zip
feat(metadata): read image dimensions
Diffstat (limited to 'internal/metadata/dimensions.go')
-rw-r--r--internal/metadata/dimensions.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/internal/metadata/dimensions.go b/internal/metadata/dimensions.go
new file mode 100644
index 0000000..55472a0
--- /dev/null
+++ b/internal/metadata/dimensions.go
@@ -0,0 +1,32 @@
+package metadata
+
+import (
+ "fmt"
+ "image"
+ "os"
+
+ _ "image/gif"
+ _ "image/jpeg"
+ _ "image/png"
+
+ _ "golang.org/x/image/webp"
+)
+
+// readDimensions returns the dimensions of an image without decoding
+// the entire image into memory.
+func readDimensions(path string) (width, height int, err error) {
+ file, err := os.Open(path)
+ if err != nil {
+ return 0, 0, fmt.Errorf("open image: %w", err)
+ }
+ defer func() {
+ _ = file.Close()
+ }()
+
+ cfg, _, err := image.DecodeConfig(file)
+ if err != nil {
+ return 0, 0, fmt.Errorf("decode image config: %w", err)
+ }
+
+ return cfg.Width, cfg.Height, nil
+}