diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-07-13 12:10:56 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-13 12:10:56 +0530 |
| commit | 1a3e963e88a76e3bf9bdab74b251331a7edfe5cb (patch) | |
| tree | 28ef9d964210f5cd1a4eda23f6de2cb9cca45583 /internal/metadata/dimensions.go | |
| parent | f6b665f9a2633798b2317f0d42551ed0c5d0c330 (diff) | |
| parent | fa2c6d7bc239415f06064b6b65942c27445aeb61 (diff) | |
| download | galleryd-1a3e963e88a76e3bf9bdab74b251331a7edfe5cb.tar.xz galleryd-1a3e963e88a76e3bf9bdab74b251331a7edfe5cb.zip | |
Merge pull request #3 from RanXom/feat/metadata
Feat/metadata: implement metadata extraction
Diffstat (limited to 'internal/metadata/dimensions.go')
| -rw-r--r-- | internal/metadata/dimensions.go | 32 |
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 +} |