validateImageFile validates the image file path and extension
(imagePath string)
| 351 | |
| 352 | // validateImageFile validates the image file path and extension |
| 353 | func validateImageFile(imagePath string) error { |
| 354 | if imagePath == "" { |
| 355 | return nil // No validation needed if no image file specified |
| 356 | } |
| 357 | |
| 358 | // Check if file already exists |
| 359 | if _, err := os.Stat(imagePath); err == nil { |
| 360 | return fmt.Errorf(i18n.T("image_file_already_exists"), imagePath) |
| 361 | } |
| 362 | |
| 363 | // Check file extension |
| 364 | ext := strings.ToLower(filepath.Ext(imagePath)) |
| 365 | validExtensions := []string{".png", ".jpeg", ".jpg", ".webp"} |
| 366 | |
| 367 | if slices.Contains(validExtensions, ext) { |
| 368 | return nil // Valid extension found |
| 369 | } |
| 370 | |
| 371 | return fmt.Errorf(i18n.T("invalid_image_file_extension"), ext) |
| 372 | } |
| 373 | |
| 374 | // validateImageParameters validates image generation parameters |
| 375 | func validateImageParameters(imagePath, size, quality, background string, compression int) error { |