base image + skeleton for loading config file
This commit is contained in:
parent
fc1144cb1d
commit
11983d971b
26
config.go
26
config.go
@ -1,8 +1,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Method string
|
Method string `json:method`
|
||||||
OutputDir string
|
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
|
var ConfigRegister Config
|
||||||
|
10
main.go
10
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"image"
|
||||||
_ "image/jpeg"
|
_ "image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
)
|
)
|
||||||
@ -10,10 +11,17 @@ func main() {
|
|||||||
// command line arguments
|
// command line arguments
|
||||||
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun")
|
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun")
|
||||||
flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
// get two random images and load them
|
// 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())
|
img2 := loadImage(getRandomImage())
|
||||||
|
|
||||||
// pool of workers unionizing, ready to blend a new picture using the power of friendship
|
// pool of workers unionizing, ready to blend a new picture using the power of friendship
|
||||||
|
Loading…
Reference in New Issue
Block a user