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 }