pixelweaver/config.go

68 lines
2.2 KiB
Go
Raw Normal View History

package main
import (
"encoding/json"
2022-05-01 21:30:35 +02:00
"flag"
"fmt"
"os"
"strconv"
"strings"
)
type Config struct {
Method string `json:method`
OutputDir string `json:outputdir`
InputDir string `json:inputdir`
BaseImage string `json:baseimage`
Dimensions string `json:dimensions`
OutputWidth int `json:output_width`
OutputHeight int `json:output_height`
2022-05-01 17:49:51 +02:00
Grayscale bool
2022-05-01 22:20:25 +02:00
Sepia bool
Amount int
2022-05-01 21:30:35 +02:00
Quiet bool
}
// 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)
}
// Set output file dimensions using string symbol (<width>x<height>)
func (c *Config) SetOutputDimensions() {
split := strings.Split(c.Dimensions, "x")
width, _ := strconv.Atoi(split[0])
height, _ := strconv.Atoi(split[1])
c.OutputWidth = width
c.OutputHeight = height
}
2022-05-01 21:30:35 +02:00
func initConfigRegister() {
// command line arguments
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun")
flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory")
flag.StringVar(&ConfigRegister.InputDir, "input", "/home/gator/Photos", "Input directory. Where to look the images from")
flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set")
flag.StringVar(&ConfigRegister.Dimensions, "dimensions", "1280x1024", "Out image dimensions. <width>x<height>")
flag.BoolVar(&ConfigRegister.Grayscale, "grayscale", false, "Output image in shade of gray (around 50)")
2022-05-01 22:20:25 +02:00
flag.BoolVar(&ConfigRegister.Sepia, "sepia", false, "Output image with sepia tone")
2022-05-01 21:30:35 +02:00
flag.IntVar(&ConfigRegister.Amount, "amount", 2, "Number of images to blend together")
flag.BoolVar(&ConfigRegister.Quiet, "quiet", false, "No progress messages")
flag.Parse()
// set output's width and height
ConfigRegister.SetOutputDimensions()
}
// global register to acccess configuration values
var ConfigRegister Config