Created
May 11, 2019 16:05
-
-
Save jonwinton/cb1a44778abb19015d7e9089ef5d1b7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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