MCPcopy
hub / github.com/danielmiessler/Fabric / validateImageParameters

Function validateImageParameters

internal/cli/flags.go:375–432  ·  view source on GitHub ↗

validateImageParameters validates image generation parameters

(imagePath, size, quality, background string, compression int)

Source from the content-addressed store, hash-verified

373
374// validateImageParameters validates image generation parameters
375func validateImageParameters(imagePath, size, quality, background string, compression int) error {
376 if imagePath == "" {
377 // Check if any image parameters are specified without --image-file
378 if size != "" || quality != "" || background != "" || compression != 0 {
379 return errors.New(i18n.T("image_parameters_require_image_file"))
380 }
381 return nil
382 }
383
384 // Validate size
385 if size != "" {
386 validSizes := []string{"1024x1024", "1536x1024", "1024x1536", "auto"}
387 valid := slices.Contains(validSizes, size)
388 if !valid {
389 return fmt.Errorf(i18n.T("invalid_image_size"), size)
390 }
391 }
392
393 // Validate quality
394 if quality != "" {
395 validQualities := []string{"low", "medium", "high", "auto"}
396 valid := slices.Contains(validQualities, quality)
397 if !valid {
398 return fmt.Errorf(i18n.T("invalid_image_quality"), quality)
399 }
400 }
401
402 // Validate background
403 if background != "" {
404 validBackgrounds := []string{"opaque", "transparent"}
405 valid := slices.Contains(validBackgrounds, background)
406 if !valid {
407 return fmt.Errorf(i18n.T("invalid_image_background"), background)
408 }
409 }
410
411 // Get file format for format-specific validations
412 ext := strings.ToLower(filepath.Ext(imagePath))
413
414 // Validate compression (only for jpeg/webp)
415 if compression != 0 { // 0 means not set
416 if ext != ".jpg" && ext != ".jpeg" && ext != ".webp" {
417 return fmt.Errorf(i18n.T("image_compression_jpeg_webp_only"), ext)
418 }
419 if compression < 0 || compression > 100 {
420 return fmt.Errorf(i18n.T("image_compression_range_error"), compression)
421 }
422 }
423
424 // Validate background transparency (only for png/webp)
425 if background == "transparent" {
426 if ext != ".png" && ext != ".webp" {
427 return fmt.Errorf(i18n.T("transparent_background_png_webp_only"), ext)
428 }
429 }
430
431 return nil
432}

Callers 2

BuildChatOptionsMethod · 0.85

Calls 1

TFunction · 0.92

Tested by 1