2022-04-26 13:51:49 +02:00
|
|
|
package main
|
|
|
|
|
2022-05-01 09:36:52 +02:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-05-01 21:30:35 +02:00
|
|
|
"flag"
|
2022-05-01 09:36:52 +02:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-05-01 15:33:55 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-05-01 09:36:52 +02:00
|
|
|
)
|
|
|
|
|
2022-04-26 13:51:49 +02:00
|
|
|
type Config struct {
|
2022-05-01 15:33:55 +02:00
|
|
|
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
|
2022-05-01 20:52:03 +02:00
|
|
|
Amount int
|
2022-05-01 21:30:35 +02:00
|
|
|
Quiet bool
|
2022-05-01 09:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2022-04-26 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
2022-05-01 15:33:55 +02:00
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
|
2022-05-01 09:36:52 +02:00
|
|
|
// global register to acccess configuration values
|
2022-04-26 13:51:49 +02:00
|
|
|
var ConfigRegister Config
|