Created
February 16, 2016 19:58
-
-
Save odeke-em/911f922deea571605fdc to your computer and use it in GitHub Desktop.
Util for validating GIF resources.
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
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