title: Animated gif not saved correctly
body: <p>I use this snippet to save image files encoded as base64 and sent from json:</p>
  
  <pre><code>func SaveBase64ImageToDisk(imageString string) (interface{}, error) {
      imageExt := strings.ToLower(strings.Split(strings.Split(imageString, ";")[0], "/")[1])
      imageData := strings.Split(imageString, ";base64,")[1]
      imageReader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(imageData))
  
      if decodedImage, _, err := image.Decode(imageReader); err != nil {
          return nil, err
      } else {
          imageFileName, _ := _saveImage(imageExt, &amp;decodedImage)
  
          return imageFileName.(string), nil
      }
  }
  
      func _saveImage(imageExt string, decodedImage *image.Image) (interface{}, error) {
  
          dir, err := os.Getwd()
          if err != nil {
              log.Fatal(err)
          }
  
          path := dir + "/media/photos/"
          imageFileName := getRandomFileName("randomstr") + "." + imageExt
          if imageFile, err := os.Create(path + imageFileName); err != nil {
              return nil, err
          } else {
              defer imageFile.Close()
              if imageExt == "png" {
                  if err = png.Encode(imageFile, *decodedImage); err != nil {
                      return nil, err
                  }
              } else if imageExt == "jpg" {
                  if err = jpeg.Encode(imageFile, *decodedImage, nil); err != nil {
                      return nil, err
                  }
              } else if imageExt == "gif" {
                  if err = gif.Encode(imageFile, *decodedImage, nil); err != nil {
                      return nil, err
                  }
              }
              return imageFileName, nil
          }
      }
  
      func getRandomFileName(prefix string) string {
          rand.Seed(time.Now().UTC().UnixNano())
          l := len(prefix)
          result := make([]byte, l)
          for i := 0; i &lt; l; i++ {
              result[i] = CHARS[rand.Intn(len(CHARS))]
          }
          return string(result)
      }
  </code></pre>
  
  <p>It works fine for <code>png</code> and <code>jpeg</code> but animated <code>gif</code> images are saved as a still image, or are not displayed at all at some image viewers. I'm wondering how can I fix this? </p>