From 968935e00f3dca2d0b64ca7eaf1b411c9ad1a344 Mon Sep 17 00:00:00 2001 From: hmj6502 Date: Sun, 28 Dec 2025 20:16:20 +0000 Subject: initial commit --- .gitmodules | 3 +++ Makefile | 10 ++++++++++ README.md | 12 ++++++++++++ colors | 1 + rand_wall.sh | 10 ++++++++++ wall_gen.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 .gitmodules create mode 100644 Makefile create mode 100644 README.md create mode 160000 colors create mode 100755 rand_wall.sh create mode 100755 wall_gen.sh diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0e9fe95 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "colors"] + path = colors + url = git://git.2f30.org/colors diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..773e04c --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +DEPS:=./colors/colors + +all: $(DEPS) + +clean: + $(MAKE) -C colors/ clean + +./colors/colors: + $(MAKE) -C colors/ + @echo "install colors or add it to your path!" diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ac6fcb --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +* make wallpapers based on album covers! +takes most promiment color in album cover, centres cover and sets it as +wallpaper. + +* dependencies +- X11 +- xwallpaper +- colors (https://git.2f30.org/colors/) +- imagemagick + +* TODO +- add dmenu selector of image names diff --git a/colors b/colors new file mode 160000 index 0000000..8edb183 --- /dev/null +++ b/colors @@ -0,0 +1 @@ +Subproject commit 8edb1839c1d2a62fbd1d4447f802997896c2b0c0 diff --git a/rand_wall.sh b/rand_wall.sh new file mode 100755 index 0000000..062d231 --- /dev/null +++ b/rand_wall.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# generate a wallpaper using wall_gen.sh using a random image from a directory +# (including subdirectories; defaults to ~/Pictures/albums if no directory given) + +if [ $# -eq 0 ]; then + IMG_DIR="$HOME/Pictures/albums" +else + IMG_DIR="$1" +fi +wall_gen.sh $(find "$IMG_DIR" -not -path '*/.*' -type f -printf "%p\n" | sort -R | sed -n '1p') diff --git a/wall_gen.sh b/wall_gen.sh new file mode 100755 index 0000000..75b9114 --- /dev/null +++ b/wall_gen.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# requires imagemagick and colors (https://git.2f30.org/colors/) + +# resolution of wallpaper +XMAX=1920 +YMAX=1080 + +if ! [ -f "$1" ]; then + printf "ERROR: file not found\n" + exit 1 +fi + +# get resolution of cover +RES=$(identify "$1" | awk '{print $3}') +X=$(echo $RES | awk -F "x" '{print $1}') +Y=$(echo $RES | awk -F "x" '{print $2}') + +X_RES=$(echo "$XMAX"/4 | bc) # x to resize to if x > y +Y_RES=$(echo "$YMAX"/2 | bc) # y to resize to if y > x should be ~400 +FACT= # factor to change scale by; in %; defined next + +# FACT will depend on X if cover is squarish, or on Y if it is more rectangular +if [ $Y -gt $(echo "scale = 0; $X * 1.1 / 1" | bc) ]; then + FACT="$(echo "scale = 2; $Y_RES/$Y * 100 / 1" | bc)%" # divide by 1 forces bc to round +else + FACT="$(echo "scale = 2; $X_RES/$X * 100 / 1" | bc)%" # divide by 1 forces bc to round +fi + +mkdir -p /tmp/wall_gen +# get name and put .png to automatically convert to png if necessary +NAME=$(echo "$(basename "$1")" | sed -e 's/.jpg/.png/' -e 's/.jpeg/.png/' -e 's/.gif/.png/') +magick "$1" -resize "$FACT" /tmp/wall_gen/"$NAME" +FILE="/tmp/wall_gen/$NAME" +RES=$(identify "$FILE" | awk '{print $3}') +X=$(echo "$RES" | awk -F "x" '{print $1}') +Y=$(echo "$RES" | awk -F "x" '{print $2}') + +# get how size of border; divide by 2 as border size is only one side's +XPLUS=$(echo "(1920-$X)/2" | bc) +YPLUS=$(echo "(1080-$Y)/2" | bc) + +COLOR=$(cat "$FILE" | colors -n 1) + +NAME="$(echo $NAME | sed 's/.png//')-wall.png" + +magick "$FILE" -bordercolor "$COLOR" -border "$XPLUS"x"$YPLUS" /tmp/wall_gen/$NAME +xwallpaper --zoom /tmp/wall_gen/$NAME -- cgit v1.2.3