title: How to covert a []byte object to an image and store it as a jpeg image on disk
body: <p>I am trying to convert an []byte object to an image and save it as a jpeg in Golang. I tried to use <code>Decode</code> function of image but it always returns <code>&lt;nil&gt;</code>. </p>
  
  <pre><code>func saveFrames(imgByte []byte) {
      img, _, _ := image.Decode(bytes.NewReader(imgByte))
     out, err := os.Create("./img.jpeg")
  
     if err != nil {
               fmt.Println(err)
               os.Exit(1)
     }
     err = jpeg.Encode(out, img)
     if err != nil {
              fmt.Println(err)
              os.Exit(1)
     }
  }
  </code></pre>