base image + skeleton for loading config file

This commit is contained in:
Ali Gator 2022-05-01 09:36:52 +02:00
parent fc1144cb1d
commit 11983d971b
2 changed files with 33 additions and 3 deletions

View File

@ -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

10
main.go
View File

@ -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