-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
103 lines (95 loc) · 2.33 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
package main
import (
"log"
"os"
"strings"
"time"
"github.com/prgres/img2asci/pkg/img2asci"
"github.com/urfave/cli/v2"
)
func main() {
flags := []cli.Flag{
&cli.IntFlag{
Name: "width",
Aliases: []string{"wx"},
Value: 80,
Usage: "width of output image ",
},
&cli.IntFlag{
Name: "height",
Aliases: []string{"hx"},
Value: 0,
Usage: "width of output image",
},
&cli.Float64Flag{
Name: "sharp",
Aliases: []string{"vs"},
Value: img2asci.DeafultSharp,
Usage: "preprocessing sharpening value",
},
&cli.Float64Flag{
Name: "bright",
Aliases: []string{"vb"},
Value: img2asci.DeafultBright,
Usage: "preprocessing bright value",
},
&cli.Float64Flag{
Name: "contrast",
Aliases: []string{"vc"},
Value: img2asci.DeafultContrast,
Usage: "preprocessing contrast value",
},
&cli.StringFlag{
Name: "outputFilePath",
Aliases: []string{"o"},
Value: "./output.txt",
Usage: "name of output file",
},
&cli.StringFlag{
Name: "grayScaleAsciTable",
Value: img2asci.DeafultGrayScale,
Usage: "override gray scale with ASCI characters",
},
&cli.BoolFlag{
Name: "term",
Aliases: []string{"t"},
Value: false,
Usage: "if print to term",
},
}
app := &cli.App{
EnableBashCompletion: true,
Name: "img2asci",
Usage: "ASCI ART converter",
Description: "Simple but yet very powerfull converter from ordinary, plain images to beatiful ASCI art",
Flags: flags,
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: "M. Więcek",
},
},
Action: func(c *cli.Context) error {
if c.NArg() == 0 {
return cli.ShowAppHelp(c)
}
inputFile := strings.TrimSpace(c.Args().First())
outputFile := c.String("outputFilePath")
img := &img2asci.Config{
Term: c.Bool("term"),
ProcessingValues: &img2asci.ProcessingValues{
Width: c.Int("width"),
Height: c.Int("height"),
Sharp: c.Float64("sharp"),
Bright: c.Float64("bright"),
Contrast: c.Float64("contrast"),
GrayScaleAsciTable: c.String("grayScaleAsciTable"),
},
}
return img.Process(inputFile, outputFile)
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}