~dricottone/image2ascii

ref: ddef6b97673e0b11e2ceddc51cdea3820757f061 image2ascii/image2ascii.go -rw-r--r-- 1.5 KiB
ddef6b97 — qeesung update travis yml 6 years ago
                                                                                
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
package main

import (
	"flag"
	"fmt"
	"github.com/qeesung/image2ascii/convert"
	_ "image/jpeg"
	_ "image/png"
	"os"
)

var imageFilename string
var ratio float64
var expectedWidth int
var expectedHeight int
var fitScreen bool
var colored bool

func init() {
	flag.StringVar(&imageFilename, "f", "", "Image filename to be convert")
	flag.Float64Var(&ratio, "r", 1, "Ratio to scale the image, ignored when use -w or -g")
	flag.IntVar(&expectedWidth, "w", -1, "Expected image width, -1 for image default width")
	flag.IntVar(&expectedHeight, "g", -1, "Expected image height, -1 for image default height")
	flag.BoolVar(&fitScreen, "s", true, "Fit the terminal screen, ignored when use -w, -g, -r")
	flag.BoolVar(&colored, "c", true, "Colored the ascii when output to the terminal")
	flag.Usage = usage
}

func main() {
	flag.Parse()

	if imageFilename == "" {
		usage()
		return
	}
	// config  the options
	convertOptions := &convert.Options{
		Ratio:          ratio,
		ExpectedHeight: expectedHeight,
		ExpectedWidth:  expectedWidth,
		FitScreen:      fitScreen,
		Colored:        colored,
	}
	fmt.Print(convert.ImageFile2ASCIIString(imageFilename, convertOptions))
}

func usage() {
	fmt.Fprintf(os.Stderr, `image2ascii version: image2ascii/1.0.0 
>> HomePage: https://github.com/qeesung/image2ascii
>> Issue   : https://github.com/qeesung/image2ascii/issues
>> Author  : qeesung
Usage: image2ascii [-s] -f <filename> -r <ratio> -w <width> -g <height>

Options:
`)
	flag.PrintDefaults()
}