补全图像尺寸预处理约束

This commit is contained in:
2026-06-07 23:55:25 +08:00
parent 4d1a01ec71
commit b7500d81d1
4 changed files with 442 additions and 0 deletions
@@ -464,6 +464,46 @@ func parsePositiveFloat(value string) float64 {
return out
}
func positiveFloatFromAny(value any) float64 {
switch typed := value.(type) {
case int:
return float64(typed)
case int64:
return float64(typed)
case float64:
return typed
case string:
return parsePositiveFloat(typed)
default:
return 0
}
}
func positiveIntegerFromAny(value any) int {
number := positiveFloatFromAny(value)
if number <= 0 {
return 0
}
return int(math.Round(number))
}
func parsePixelSizeString(value string) (int, int, bool) {
value = strings.TrimSpace(strings.ToLower(value))
if value == "" || isEmptyParamString(value) {
return 0, 0, false
}
parts := strings.Split(value, "x")
if len(parts) != 2 {
return 0, 0, false
}
width := positiveIntegerFromAny(parts[0])
height := positiveIntegerFromAny(parts[1])
if width <= 0 || height <= 0 {
return 0, 0, false
}
return width, height, true
}
func isEmptyParamString(value string) bool {
normalized := strings.ToLower(strings.TrimSpace(value))
return normalized == "null" || normalized == "undefined"