/
main.go
153 lines (138 loc) · 2.96 KB
/
main.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package main
import (
"github.com/AlecAivazis/survey/v2"
"github.com/yeqown/infrastructure/pkg/fontutil"
"github.com/yeqown/log"
)
func init() {
// default ignore all logs
log.SetLogLevel(log.LevelFatal)
}
func main() {
var (
bgQA = bgQsAnswer{}
contentQA = contentQsAnswer{}
outputQA = outputQsAnswer{}
err error
)
// perform the questions
if err = survey.Ask(bgQs, &bgQA); err != nil {
log.Error(err)
return
}
if err = survey.Ask(contentQs, &contentQA); err != nil {
log.Error(err)
return
}
if err = survey.Ask(outputQs, &outputQA); err != nil {
log.Error(err)
return
}
img := NewImg(
newbackground(bgQA.Color, bgQA.W, bgQA.H),
newtext(0, 0, contentQA.Size, contentQA.FontFamily, contentQA.Color, contentQA.Content),
outputOption{filename: outputQA.Filename, format: ImgFormat(outputQA.Format)},
)
// generating img and save
if err := img.Save(); err != nil {
log.Error(err)
}
}
// the background setting to ask
var bgQs = []*survey.Question{
{
Name: "color",
Prompt: &survey.Select{
Message: "Choose a background color:",
Options: getDefaultColorList(),
Default: "white",
},
},
{
Name: "w",
Prompt: &survey.Input{
Message: "Input background width: (default: 1600)",
Default: "1600",
},
Validate: survey.Required,
Transform: survey.Title,
},
{
Name: "h",
Prompt: &survey.Input{
Message: "Input background height: (default: 300)",
Default: "300",
},
Validate: survey.Required,
Transform: survey.Title,
},
}
type bgQsAnswer struct {
Color string `survey:"color"`
W int `survey:"w"`
H int `survey:"h"`
}
// the text content setting to ask
var contentQs = []*survey.Question{
{
Name: "content",
Prompt: &survey.Input{Message: "Input your content:"},
Validate: survey.Required,
Transform: survey.Title,
},
{
Name: "color",
Prompt: &survey.Select{
Message: "Choose the text color:",
Options: getDefaultColorList(),
Default: "black",
},
},
{
Name: "fontfamily",
Prompt: &survey.Select{
Message: "Choose a font:",
Options: fontutil.GetSysFontList(),
Default: fontutil.GetSysDefaultFont(),
},
},
{
Name: "size",
Prompt: &survey.Input{
Message: "Input font size (px):",
Default: "32",
},
Validate: survey.Required,
Transform: survey.Title,
},
}
type contentQsAnswer struct {
Content string `survey:"content"`
Color string `survey:"color"`
FontFamily string `survey:"fontfamily"`
Size int `survey:"size"`
}
// the text output setting to ask
var outputQs = []*survey.Question{
{
Name: "filename",
Prompt: &survey.Input{
Message: "Input output filename:",
Default: "untitled",
},
Validate: survey.Required,
Transform: survey.Title,
},
{
Name: "format",
Prompt: &survey.Select{
Message: "Choose a output format:",
Options: []string{"jpeg", "png"},
Default: "jpeg",
},
},
}
type outputQsAnswer struct {
Filename string `survey:"filename"`
Format string `survey:"format"`
}