summaryrefslogtreecommitdiff
path: root/internal/comic/pageframe.go
blob: 82ab36357c532d48d901654e8196b94e9365109c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package comic

import (
	"fmt"
	"strconv"
	"strings"
)

// DescribePageFrame returns human-readable page shape text for image prompts,
// derived from a Gemini-style aspect ratio such as "16:9" or "2:3".
func DescribePageFrame(aspectRatio string) string {
	aspectRatio = strings.TrimSpace(aspectRatio)
	if aspectRatio == "" {
		aspectRatio = comicPageAspectRatio
	}
	parts := strings.Split(aspectRatio, ":")
	if len(parts) != 2 {
		return fmt.Sprintf("%s format", aspectRatio)
	}
	w, errW := strconv.Atoi(strings.TrimSpace(parts[0]))
	h, errH := strconv.Atoi(strings.TrimSpace(parts[1]))
	if errW != nil || errH != nil || w <= 0 || h <= 0 {
		return fmt.Sprintf("%s format", aspectRatio)
	}
	switch {
	case w < h:
		if w == 3 && h == 4 {
			return "portrait 3:4 format (ISO A4–class sheet: 210×297 mm target; image API uses 3:4 as the closest standard ratio)"
		}
		return fmt.Sprintf("portrait %s format (tall comic book page proportions)", aspectRatio)
	case w > h:
		return fmt.Sprintf("landscape %s format (widescreen)", aspectRatio)
	default:
		return fmt.Sprintf("square %s format", aspectRatio)
	}
}