Skip to content

Instantly share code, notes, and snippets.

@odeke-em
Created February 16, 2016 19:58
Show Gist options
  • Save odeke-em/911f922deea571605fdc to your computer and use it in GitHub Desktop.
Save odeke-em/911f922deea571605fdc to your computer and use it in GitHub Desktop.
Util for validating GIF resources.
package main
import (
"fmt"
"image/gif"
"net/http"
"os"
)
func decodeGIF(url string) (*gif.GIF, error) {
res, err := http.Get(url)
if err != nil {
return nil, err
}
if res.Close && res.Body != nil {
defer res.Body.Close()
}
return gif.DecodeAll(res.Body)
}
func main() {
urls := []string{"http://i.imgur.com/WWfGR9l.gif"}
if len(os.Args) >= 2 {
urls = os.Args[1:]
}
for _, url := range urls {
_, err := decodeGIF(url)
if err != nil {
fmt.Fprintf(os.Stderr, "%s gif decoding failed with err %v\n", url, err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment