title: Get image size with golang
body: <p>I'm new to golang and I'm trying to get the image size of all the images listed in a directory. That's what I've done</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "image"
      _ "image/jpeg"
      "io/ioutil"
      "os"
  )
  
  const dir_to_scan string = "/home/da/to_merge"
  
  func main() {
      files, _ := ioutil.ReadDir(dir_to_scan)
      for _, filepath := range files {
  
          if reader, err := os.Open(filepath.Name()); err != nil {
              defer reader.Close()
              im, _, err := image.DecodeConfig(reader)
              if err != nil {
                  fmt.Fprintf(os.Stderr, "%s: %v\n", filepath.Name(), err)
                  continue
              }
              fmt.Printf("%s %d %d\n", filepath.Name(), im.Width, im.Height)
          } else {
              fmt.Println("Impossible to open the file")
          }
      }
  }
  </code></pre>
  
  <p>I've an error when it comes to <code>image.DecodeConfig</code>, that says <code>image: unknown format</code>
  Has someone an idea about the proper way to do it?
  In the docs here <a href="http://golang.org/src/pkg/image/format.go?s=2676:2730#L82" rel="noreferrer">http://golang.org/src/pkg/image/format.go?s=2676:2730#L82</a> says that i should pass a <code>io.Reader</code> as argument, and that's what i'm doing. </p>