mirror of https://gitee.com/answerdev/answer.git
Update file_type.go
This commit is contained in:
parent
541c35e827
commit
de6a633248
|
@ -1,26 +1,25 @@
|
||||||
package checker
|
package checker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image/jpeg"
|
"image"
|
||||||
"image/png"
|
_ "image/gif" // use init to support decode jpeg,jpg,png,gif
|
||||||
|
_ "image/jpeg"
|
||||||
|
_ "image/png"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsSupportedImageFile currently answers support image type is `image/jpeg,image/jpg,image/png`
|
// IsSupportedImageFile currently answers support image type is `image/jpeg,image/jpg,image/png, image/gif`
|
||||||
func IsSupportedImageFile(file io.Reader, ext string) bool {
|
func IsSupportedImageFile(file io.Reader, ext string) bool {
|
||||||
|
|
||||||
ext = strings.TrimPrefix(ext, ".")
|
ext = strings.TrimPrefix(ext, ".")
|
||||||
var err error
|
var err error
|
||||||
switch strings.ToUpper(ext) {
|
switch strings.ToUpper(ext) {
|
||||||
case "JPEG":
|
case "JPG", "JPEG", "PNG", "GIF": // only allow for `image/jpeg,image/jpg,image/png, image/gif`
|
||||||
_, err = jpeg.Decode(file)
|
_, _, err = image.Decode(file)
|
||||||
case "PNG":
|
|
||||||
_, err = png.Decode(file)
|
|
||||||
case "ICO":
|
case "ICO":
|
||||||
// TODO: There is currently no good Golang library to parse whether the image is in ico format.
|
// TODO: There is currently no good Golang library to parse whether the image is in ico format.
|
||||||
return true
|
return true
|
||||||
case "JPG":
|
|
||||||
return true
|
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue