-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
50 lines (44 loc) · 986 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
"github.com/zyxar/image2ascii/ascii"
)
var (
width = flag.Int("w", 0, "set image width")
height = flag.Int("h", 0, "set image height")
color = flag.Bool("c", false, "enable colour mode")
flipx = flag.Bool("x", false, "enable flip-x mode")
flipy = flag.Bool("y", false, "enable flip-y mode")
invert = flag.Bool("i", false, "enable invert mode")
)
func main() {
flag.Parse()
if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "Usage: image2ascii [options] {IMAGE FILE}\n")
flag.PrintDefaults()
os.Exit(1)
}
r, err := os.Open(flag.Arg(0))
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
defer r.Close()
opt := ascii.Options{
Width: *width,
Height: *height,
Color: *color,
Invert: *invert,
Flipx: *flipx,
Flipy: *flipy}
a, err := ascii.Decode(r, opt)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
if _, err = a.WriteTo(os.Stdout); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}