DecodeAndCheckImageFile currently answers support image type is `image/jpeg, image/jpg, image/png, image/gif, image/webp`
(localFilePath string, maxImageMegapixel int)
| 45 | // DecodeAndCheckImageFile currently answers support image type is |
| 46 | // `image/jpeg, image/jpg, image/png, image/gif, image/webp` |
| 47 | func 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 | |
| 68 | func decodeAndCheckImageFile(localFilePath string, maxImageMegapixel int, ext string, |
| 69 | checker func(file io.Reader, ext string, maxImageMegapixel int) error) bool { |
no test coverage detected