working random wallpaper

This commit is contained in:
andrzej 2024-10-27 01:48:17 +02:00
parent 0655e6a1ee
commit 58aba48e3c
6 changed files with 76 additions and 0 deletions

7
config.json Normal file
View File

@ -0,0 +1,7 @@
{
"colorize":[ 247,40,60 ],
"contrast":-35,
"gamma":0.8,
"root":"/home/andrzej/bgs"
}

BIN
curr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module go-img
go 1.23.2
require github.com/disintegration/gift v1.2.1

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc=
github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI=

BIN
in.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

62
main.go Normal file
View File

@ -0,0 +1,62 @@
package main
import (
"encoding/json"
"fmt"
"log"
"os"
)
func main() {
var err error
config := loadConfig()
//get working directory
wd, err := os.Getwd()
if err != nil {
log.Fatal("couldn't find working directory", err)
}
curr := wd + "/curr.png"
// apply curr.png if already preloaded
err = hyprpaperWallpaper(curr)
if err != nil {
//preload curr.png if not
err = hyprpaperPreload(curr)
if err != nil {
fmt.Println("could not preload (this is fine)", err)
}
}
dir := config.Root + "/chsck"
randomImg, _ := getRandomFile(dir)
img := loadImage(randomImg)
dst := processImage(img, config)
saveImage("curr.png", dst)
path := wd + "/curr.png"
err = hyprpaperPreload(path)
if err != nil {
log.Fatal("preload failed!", err)
}
err = hyprpaperWallpaper(path)
if err != nil {
log.Fatal("set wallpaper failed!", err)
}
}
func loadConfig() Config {
configRaw, err := os.ReadFile("./config.json")
if err != nil {
log.Fatal("Couldn't open config file!", err)
}
var config Config
err = json.Unmarshal(configRaw, &config)
if err != nil {
log.Fatal("Couldn't unmarshal config!", err)
}
return config
}