Files
moteva/server/internal/domain/design/image_size.go
T
root 44406b72db Initial commit: img-infinite-canvas AI design workbench MVP
Moteva-style AI design workbench replica. Home prompt creates a project;
the project page provides an infinite canvas with node drag, zoom/pan,
a design chat panel, history replay, image asset upload, and project
save/regenerate.

- Backend: go-zero, DDD layering, sqlc/pgx, optional PostgreSQL; memory
  or Redis cache; asynq job queue; MinIO/S3/R2/OSS object storage;
  sky-valley/pi agent runtime adapter.
- Frontend: Next.js App Router + Vite artifact build, TypeScript, i18n,
  shadcn/ui components, auth (OTP/Turnstile/Google/WeChat).
- Deploy: Docker Compose and k3s manifests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-07 23:15:37 +08:00

41 lines
946 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package design
import (
"strconv"
"strings"
)
const (
DefaultGeneratedImageSize = "1024x1024"
DefaultGeneratedImageWidth = 1024
DefaultGeneratedImageHeight = 1024
)
func ParseImageSize(size string) (float64, float64, bool) {
size = strings.ToLower(strings.TrimSpace(size))
if size == "" {
return 0, 0, false
}
size = strings.NewReplacer(" ", "", "\t", "", "\n", "", "×", "x", "*", "x").Replace(size)
parts := strings.Split(size, "x")
if len(parts) != 2 {
return 0, 0, false
}
width, err := strconv.ParseFloat(parts[0], 64)
if err != nil || width <= 0 {
return 0, 0, false
}
height, err := strconv.ParseFloat(parts[1], 64)
if err != nil || height <= 0 {
return 0, 0, false
}
return width, height, true
}
func GeneratedImageDimensions(size string) (float64, float64) {
if width, height, ok := ParseImageSize(size); ok {
return width, height
}
return DefaultGeneratedImageWidth, DefaultGeneratedImageHeight
}