validateImageFile rejects a path that exists or has an extension other than png, jpeg, jpg, or webp.
(imagePath string)
| 330 | |
| 331 | // validateImageFile rejects a path that exists or has an extension other than png, jpeg, jpg, or webp. |
| 332 | func validateImageFile(imagePath string) error { |
| 333 | if imagePath == "" { |
| 334 | return nil |
| 335 | } |
| 336 | |
| 337 | if _, err := os.Stat(imagePath); err == nil { |
| 338 | return fmt.Errorf(i18n.T("image_file_already_exists"), imagePath) |
| 339 | } |
| 340 | |
| 341 | ext := strings.ToLower(filepath.Ext(imagePath)) |
| 342 | validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"} |
| 343 | |
| 344 | if slices.Contains(validExtensions, ext) { |
| 345 | return nil |
| 346 | } |
| 347 | |
| 348 | return fmt.Errorf(i18n.T("invalid_image_file_extension"), ext) |
| 349 | } |
| 350 | |
| 351 | func validateImageParameters(imagePath, size, quality, background string, compression int) error { |
| 352 | if imagePath == "" { |