Skip to content

Instantly share code, notes, and snippets.

@jonwinton
Created May 11, 2019 16:05
Show Gist options
  • Select an option

  • Save jonwinton/cb1a44778abb19015d7e9089ef5d1b7e to your computer and use it in GitHub Desktop.

Select an option

Save jonwinton/cb1a44778abb19015d7e9089ef5d1b7e to your computer and use it in GitHub Desktop.
func sendSingleFrame(c echo.Context) error {
// Initialize a Buffer
buf := new(bytes.Buffer)
// Grab the file from the filesystem
imgFile, _ := os.Open("cool.gif")
// If you try and decode the image you'll
// only find the first frame of the gif
g, _ := gif.Decode(imgFile)
// Encode to the Buffer
err := gif.Encode(buf, g, nil)
// Print an error
if err != nil {
fmt.Println(err)
return echo.NewHTTPError(http.StatusInternalServerError, "An issue occured, check the server logs")
}
// Send it to the client
return c.Stream(http.StatusOK, "image/gif", buf)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment