From 3c5ecdf9cf34fd730705abcffa7186c969fa1021 Mon Sep 17 00:00:00 2001 From: qeesung <1245712564@qq.com> Date: Sat, 20 Oct 2018 22:33:23 +0800 Subject: [PATCH] Parse the cli args --- image2ascii.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 image2ascii.go diff --git a/image2ascii.go b/image2ascii.go new file mode 100644 index 0000000..e3ddf51 --- /dev/null +++ b/image2ascii.go @@ -0,0 +1,50 @@ +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 + +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.Usage = usage +} + +func main() { + flag.Parse() + + // config the options + convertOptions := &convert.Options{ + Ratio: ratio, + ExpectedHeight: expectedHeight, + ExpectedWidth: expectedWidth, + FitScreen: fitScreen, + } + 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 -r -w -g + +Options: +`) + flag.PrintDefaults() +} -- 2.45.2