go get github.com/mushroomsir/image-type
Format | Type | MimeType | Dimension |
---|---|---|---|
jpg | support | support | support |
png | support | support | support |
gif | support | support | support |
bmp | support | support | support |
webp | support | support | support |
ico | support | support | no |
package main
import (
"fmt"
imageType "github.com/mushroomsir/image-type"
)
func main() {
// imageType.ParseFile(file *os.File)
// imageType.ParseReader(rd io.Reader)
// imageType.Parse(bytes []byte)
res, err := imageType.ParsePath("../testdata/test.jpg")
if err == nil {
fmt.Println(res.Type) // jpg
fmt.Println(res.MimeType) // image/jpeg
fmt.Println(res.Width) // 600
fmt.Println(res.Height) // 600
} else {
fmt.Println(err)
}
}
res, _ := imageType.ParsePath("../testdata/test.jpg")
if res != nil {
fmt.Println("It's image")
}
All source code is licensed under the MIT License.