Check for corrupt image files in Go
Go has a great image library packaged with the standard distribution.
I needed to check for corrupt images in go, you can do that like so:
// importing gif, jpeg, and png for side effects
// if these imports are not there the Decode will not be able
// to detect these filetypes
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
)
_, _, err = image.Decode(file)
if err != nil {
println(f.Name() + " seems corrupt")
}
Full example to scan for bad images in the current directory: https://gist.github.com/hoffoo/7285657
Written by Marin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Go
Authors
Related Tags
#go
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#