add gif and webp support to imageChecker

This commit is contained in:
nikk gitanes
2023-05-03 00:32:50 +03:00
parent 53bb21f7d9
commit 59bcfe3843
3 changed files with 12 additions and 1 deletions

View File

@@ -2,9 +2,13 @@ package utils
import (
"image"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
"net/http"
"strings"
"golang.org/x/image/webp"
"server/log"
)
@@ -19,7 +23,11 @@ func CheckImgUrl(link string) bool {
return false
}
defer resp.Body.Close()
_, _, err = image.Decode(resp.Body)
if strings.HasSuffix(link, ".webp") {
_, err = webp.Decode(resp.Body)
} else {
_, _, err = image.Decode(resp.Body)
}
if err != nil {
log.TLogln("Error decode image:", err)
return false