mirror of https://gitee.com/answerdev/answer.git
Merge pull request #533 from buttercannfly/main
better way to decode images
This commit is contained in:
commit
6c2a288abe
2
LICENSE
2
LICENSE
|
@ -186,7 +186,7 @@
|
|||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2022 joyqi
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -34,7 +34,7 @@ Answer provides a plugin system for developers to create custom plugins and expa
|
|||
|
||||
We value your feedback and suggestions to improve our documentation. If you have any comments or questions, please feel free to contact us. We’re excited to see what you can create using our plugin system!
|
||||
|
||||
You can also check out the [officially supported plugins here](https://github.com/answerdev/plugins).
|
||||
You can also check out the [plugins here](https://github.com/answerdev/plugins).
|
||||
|
||||
|
||||
## Contributing
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
package checker
|
||||
|
||||
import (
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"image"
|
||||
_ "image/gif" // use init to support decode jpeg,jpg,png,gif
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"io"
|
||||
"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 {
|
||||
|
||||
ext = strings.TrimPrefix(ext, ".")
|
||||
var err error
|
||||
switch strings.ToUpper(ext) {
|
||||
case "JPG", "JPEG":
|
||||
_, err = jpeg.Decode(file)
|
||||
case "PNG":
|
||||
_, err = png.Decode(file)
|
||||
case "JPG", "JPEG", "PNG", "GIF": // only allow for `image/jpeg,image/jpg,image/png, image/gif`
|
||||
_, _, err = image.Decode(file)
|
||||
case "ICO":
|
||||
// TODO: There is currently no good Golang library to parse whether the image is in ico format.
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue