MCPcopy Index your code
hub / github.com/apache/answer / DecodeAndCheckImageFile

Function DecodeAndCheckImageFile

pkg/checker/file_type.go:47–66  ·  view source on GitHub ↗

DecodeAndCheckImageFile currently answers support image type is `image/jpeg, image/jpg, image/png, image/gif, image/webp`

(localFilePath string, maxImageMegapixel int)

Source from the content-addressed store, hash-verified

45// DecodeAndCheckImageFile currently answers support image type is
46// `image/jpeg, image/jpg, image/png, image/gif, image/webp`
47func DecodeAndCheckImageFile(localFilePath string, maxImageMegapixel int) bool {
48 ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(localFilePath), "."))
49 switch ext {
50 case "jpg", "jpeg", "png", "gif":
51 if !decodeAndCheckImageFile(localFilePath, maxImageMegapixel, ext, formatSpecificConfigCheck) {
52 return false
53 }
54 if !decodeAndCheckImageFile(localFilePath, maxImageMegapixel, ext, formatSpecificImageCheck) {
55 return false
56 }
57 case "webp":
58 if !decodeAndCheckImageFile(localFilePath, maxImageMegapixel, ext, webpImageConfigCheck) {
59 return false
60 }
61 if !decodeAndCheckImageFile(localFilePath, maxImageMegapixel, ext, webpImageCheck) {
62 return false
63 }
64 }
65 return true
66}
67
68func decodeAndCheckImageFile(localFilePath string, maxImageMegapixel int, ext string,
69 checker func(file io.Reader, ext string, maxImageMegapixel int) error) bool {

Callers 1

uploadImageFileMethod · 0.92

Calls 1

decodeAndCheckImageFileFunction · 0.85

Tested by

no test coverage detected