From 11983d971b43a1919c92a4b607d323c64c7bf375 Mon Sep 17 00:00:00 2001 From: Gator Date: Sun, 1 May 2022 09:36:52 +0200 Subject: [PATCH] base image + skeleton for loading config file --- config.go | 26 ++++++++++++++++++++++++-- main.go | 10 +++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index a4703fe..b7cafe9 100644 --- a/config.go +++ b/config.go @@ -1,8 +1,30 @@ package main +import ( + "encoding/json" + "fmt" + "os" +) + type Config struct { - Method string - OutputDir string + Method string `json:method` + OutputDir string `json:outputdir` + BaseImage string `json:baseimage` } +// loads configuration values from json file +func (c *Config) LoadConfigFromFile(filePath string) { + file, _ := os.Open("conf.json") + defer file.Close() + decoder := json.NewDecoder(file) + configuration := Config{} + err := decoder.Decode(&configuration) + if err != nil { + fmt.Println("error:", err) + } + fmt.Println(configuration.Method) + fmt.Println(configuration.OutputDir) +} + +// global register to acccess configuration values var ConfigRegister Config diff --git a/main.go b/main.go index 7e3a522..6c53690 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "image" _ "image/jpeg" _ "image/png" ) @@ -10,10 +11,17 @@ func main() { // command line arguments flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun") flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory") + flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set") flag.Parse() // get two random images and load them - img1 := loadImage(getRandomImage()) + var img1 image.Image + if ConfigRegister.BaseImage != "" { + img1 = loadImage(ConfigRegister.BaseImage) + } else { + img1 = loadImage(getRandomImage()) + } + img2 := loadImage(getRandomImage()) // pool of workers unionizing, ready to blend a new picture using the power of friendship