image-type
Installation
go get github.com/mushroomsir/image-type
- jpeg
- png
- gif
- bmp
- webp
- webp(lossy)
- psd
- ico
- tiff
- dds
Usage
parse image
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) // jpeg
fmt.Println(res.MimeType) // image/jpeg
fmt.Println(res.Width) // 600
fmt.Println(res.Height) // 600
} else {
fmt.Println(err)
}
}
check image
res, _ := imageType.ParsePath("../testdata/test.jpg")
if res != nil {
fmt.Println("It's image")
}
Licenses
All source code is licensed under the MIT License.