2022-02-18 20:35:11 +01:00
|
|
|
#!/bin/bash
|
|
|
|
## An Imagemagick Script To Generate Wallpapers.
|
|
|
|
## Based on https://github.com/adi1090x/canvas by Aditya Shakya (adi1090x)
|
|
|
|
## Modified by Daniel Napora for Mabox Linux to run from menu
|
2022-02-20 09:12:17 +01:00
|
|
|
# TODO: add missing options to some effects
|
|
|
|
# TODO: add ability to pick and use 4 predefined colors
|
|
|
|
# TODO: choose picker: xcolor or gpick
|
2022-02-18 20:35:11 +01:00
|
|
|
|
2022-02-20 09:12:17 +01:00
|
|
|
CONFIG_DIR="$HOME/.config/mbxutils/imgw"
|
|
|
|
CONFIG_FILE="$CONFIG_DIR/imgw.cfg"
|
|
|
|
mkdir -p $CONFIG_DIR
|
|
|
|
if [ ! -f $CONFIG_FILE ]; then
|
|
|
|
cat <<EOF > ${CONFIG_FILE}
|
|
|
|
show_preview=yes
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
source <(grep = $CONFIG_FILE)
|
2022-02-18 20:35:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
case $LANG in
|
|
|
|
pl*)
|
|
|
|
IMWG="Generator Tapet"
|
|
|
|
PICKCOLOR="Pobierz kolor z ekranu"
|
|
|
|
PICKCOLORS="Pobierz kolory z ekranu"
|
|
|
|
PICKEDCOLOR="Pobrany kolor"
|
|
|
|
PICKNEXT="Pobierz nastepny"
|
|
|
|
PICKEDALL="Generuję tapetę..."
|
2022-02-20 09:12:17 +01:00
|
|
|
SETASWP="Ustawić jako tapetę?"
|
|
|
|
YES="Tak"
|
|
|
|
NO="Nie"
|
2022-02-18 20:35:11 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
IMWG="ImageMagick Wallpaper Generator"
|
|
|
|
PICKCOLOR="Pick color from screen"
|
|
|
|
PICKCOLORS="Pick colors from screen"
|
|
|
|
PICKEDCOLOR="Picked color"
|
|
|
|
PICKNEXT="Please pick next..."
|
|
|
|
PICKEDALL="Generating Wallpaper..."
|
2022-02-20 09:12:17 +01:00
|
|
|
SETASWP="Set as Wallpaper?"
|
|
|
|
YES="Yes"
|
|
|
|
NO="No"
|
2022-02-18 20:35:11 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
DIR="$(xdg-user-dir PICTURES)/mb-canvas"
|
|
|
|
|
|
|
|
size="$(xrandr --current | grep '*' | uniq | awk '{print $1}')"
|
|
|
|
name="mb-canvas_$(date +%Y-%m-%d_%I-%M-%S).png"
|
|
|
|
#SETTER="feh --bg-scale";
|
|
|
|
SETTER="nitrogen --set-scaled --save"
|
|
|
|
#picker_app="gpick -s -o --no-newline"
|
2023-01-13 14:35:02 +01:00
|
|
|
#picker_app="xcolor"
|
|
|
|
picker_app="gpick -pso 2>/dev/null"
|
2022-02-18 20:35:11 +01:00
|
|
|
|
|
|
|
if [[ ! -d "$DIR" ]]; then
|
|
|
|
mkdir -p "$DIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
set_bg() {
|
2022-02-20 09:12:17 +01:00
|
|
|
if [[ "$show_preview" == "yes" ]];then
|
|
|
|
X="${size%x*}"
|
|
|
|
Y="${size#*x}"
|
|
|
|
P_X=$((X/4))
|
|
|
|
P_Y=$((Y/4+30))
|
|
|
|
|
|
|
|
yad --title="$SETASWP" --window-icon=mbcc --borders=0 --geometry="${P_X}x${P_Y}+200+30" \
|
|
|
|
--picture --size=fit --filename="$DIR/$name" \
|
|
|
|
--button="$NO":1 --button="$YES":2 \
|
|
|
|
|
|
|
|
ODP="$?"
|
|
|
|
|
|
|
|
[[ "$ODP" -eq "1" ]] && exit 0
|
|
|
|
if [[ "$ODP" -eq "2" ]]; then
|
|
|
|
$SETTER "$DIR/$name" && exit 0
|
|
|
|
fi
|
|
|
|
else
|
2022-02-18 20:35:11 +01:00
|
|
|
$SETTER "$DIR/$name"
|
2022-02-20 09:12:17 +01:00
|
|
|
fi
|
2022-02-18 20:35:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
## Pick the colors
|
|
|
|
color_picker() {
|
|
|
|
|
|
|
|
if [[ "$SOLID" == "true" ]]; then
|
|
|
|
notify-send.sh "$IMWG" "$PICKCOLOR" -i mbcc --expire-time=120000
|
|
|
|
color=$($picker_app)
|
2022-02-20 09:12:17 +01:00
|
|
|
elif [[ "$GRADIENT" == "true" ]] || [[ "$RGRADIENT" == "true" ]] || [[ "$TGRADIENT" == "true" ]] || "$PLASMA" == "true" ]]; then
|
2022-02-18 20:35:11 +01:00
|
|
|
notify-send.sh "$IMWG" "$PICKCOLORS: 2" -i mbcc --expire-time=120000
|
|
|
|
color1=$($picker_app)
|
|
|
|
FNAME="/tmp/${color1:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color1" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 1" "$color1\n $PICKNEXT..." --icon="$FNAME" --expire-time=120000
|
|
|
|
color2=$($picker_app)
|
|
|
|
FNAME="/tmp/${color2:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color2" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 2" "$color1\n $PICKEDALL" --icon="$FNAME" --expire-time=120000
|
|
|
|
color="$color1-$color2"
|
|
|
|
elif [[ "$BGRADIENT" == "true" ]]; then
|
|
|
|
notify-send.sh "$IMWG" "$PICKCOLORS: 4" -i mbcc --expire-time=120000
|
|
|
|
color1=$($picker_app)
|
|
|
|
FNAME="/tmp/${color1:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color1" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 1" "$color1\n $PICKNEXT..." --icon="$FNAME" --expire-time=120000
|
|
|
|
color2=$($picker_app)
|
|
|
|
FNAME="/tmp/${color2:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color2" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 2" "$color2\n $PICKNEXT..." --icon="$FNAME" --expire-time=120000
|
|
|
|
color3=$($picker_app)
|
|
|
|
FNAME="/tmp/${color3:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color3" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 3" "$color3\n $PICKNEXT..." --icon="$FNAME" --expire-time=120000
|
|
|
|
color4=$($picker_app)
|
|
|
|
FNAME="/tmp/${color4:1:6}.png"
|
|
|
|
convert -size 100x100 xc:"$color4" "$FNAME"
|
|
|
|
notify-send.sh "$PICKEDCOLOR 4" "$color4\n $PICKEDALL" --icon="$FNAME" --expire-time=120000
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Get colors
|
|
|
|
get_color() {
|
|
|
|
while true; do
|
|
|
|
color_picker
|
|
|
|
break
|
|
|
|
done
|
|
|
|
}
|
|
|
|
## Generate a solid color wallpaper
|
|
|
|
solid() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_color
|
|
|
|
color="$RCOLOR"
|
|
|
|
else
|
|
|
|
get_color
|
|
|
|
fi
|
|
|
|
convert -size "$size" canvas:"$color" "$DIR/$name"
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a linear gradient wallpaper
|
|
|
|
linear_gradient() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_color
|
|
|
|
color="$RCOLOR"
|
|
|
|
|
|
|
|
get_random_number "360"
|
|
|
|
angle="$RNUM"
|
|
|
|
else
|
|
|
|
get_color
|
2022-02-20 09:12:17 +01:00
|
|
|
angle=$(yad --center --window-icon=mbcc --title="Linear gradient" --text="\tRotation angle (default is 0):" --width=400 --scale --min-value=0 --max-value=360 --step=45 --enforce-step --inc-buttons)
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
name="linear_$name"
|
|
|
|
convert -size "$size" -define gradient:angle="${angle:-0}" gradient:"$color" "$DIR/$name"
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a radial gradient wallpaper
|
|
|
|
radial_gradient() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_color
|
|
|
|
color1="$RCOLOR"
|
|
|
|
get_random_color
|
|
|
|
color="$color1-$RCOLOR"
|
|
|
|
|
|
|
|
get_random_number "360"
|
|
|
|
angle="$RNUM"
|
|
|
|
|
|
|
|
getRandomShape
|
|
|
|
shape="$RSHAPE"
|
|
|
|
else
|
|
|
|
get_color
|
2022-02-20 09:12:17 +01:00
|
|
|
shape=$(yad --center --window-icon=mbcc --title='Choose Shape' --width=180 --height=145 --button=Ok:0 --list --no-headers --column=Shape diagonal ellipse maximum minimum | tr -d '|')
|
|
|
|
angle=$(yad --center --window-icon=mbcc --title="Radial gradient" --text="\tRotation angle:" --width=400 --scale --min-value=0 --max-value=360 --step=45 --enforce-step --inc-buttons)
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
name="radial_$name"
|
|
|
|
convert -size "$size" -define gradient:extent="${shape:-maximum}" -define gradient:angle="${angle:-0}" radial-gradient:"$color" "$DIR/$name"
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a twisted gradient wallpaper
|
|
|
|
twisted_gradient() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_color
|
|
|
|
color1="$RCOLOR"
|
|
|
|
get_random_color
|
|
|
|
color="$color1-$RCOLOR"
|
|
|
|
|
|
|
|
get_random_number "500"
|
|
|
|
twist="$RNUM"
|
|
|
|
else
|
|
|
|
get_color
|
2022-02-20 09:12:17 +01:00
|
|
|
twist=$(yad --center --window-icon=mbcc --title="Radial gradient" --text="\tTwisting amount (default is 150):" --width=400 --scale --value=150 --min-value=0 --max-value=500 --step=20 --inc-buttons)
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
name="twisted_$name"
|
|
|
|
convert -size "$size" gradient:"$color" -swirl "${twist:-150}" "$DIR/$name"
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a 4 point gradient wallpaper
|
|
|
|
bilinear_gradient() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_color
|
|
|
|
color1="$RCOLOR"
|
|
|
|
get_random_color
|
|
|
|
color2="$RCOLOR"
|
|
|
|
get_random_color
|
|
|
|
color3="$RCOLOR"
|
|
|
|
get_random_color
|
|
|
|
color4="$RCOLOR"
|
|
|
|
|
|
|
|
get_random_number "2"
|
|
|
|
if [[ "$RNUM" == "1" ]]; then
|
2022-02-20 09:12:17 +01:00
|
|
|
answer="Smooth"
|
2022-02-18 20:35:11 +01:00
|
|
|
else
|
2022-02-20 09:12:17 +01:00
|
|
|
answer="Regular"
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
get_color
|
2022-02-20 09:12:17 +01:00
|
|
|
answer=$(yad --title='Choose Style' --width=220 --height=120 --button=Ok:0 --list --no-headers --column=Style Smooth Regular | tr -d '|')
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
name="bilinear_$name"
|
2022-02-20 09:12:17 +01:00
|
|
|
if [[ $answer == "Smooth" ]] || [[ $answer == "S" ]]; then
|
|
|
|
|
2022-02-18 20:35:11 +01:00
|
|
|
convert \( xc:"$color1" xc:"$color2" +append \) \( xc:"$color3" xc:"$color4" +append \) -append -size "$size" xc: +swap -fx 'v.p{i/(w-1),j/(h-1)}' "$DIR/$name"
|
|
|
|
else
|
|
|
|
convert \( xc:"$color1" xc:"$color2" +append \) \( xc:"$color3" xc:"$color4" +append \) -append -filter triangle -resize "$size"\! "$DIR/$name"
|
|
|
|
fi
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a plasma wallpaper
|
|
|
|
plasma() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_number "3"
|
|
|
|
|
|
|
|
if [[ "$RNUM" == "1" ]]; then
|
2022-02-20 09:12:17 +01:00
|
|
|
answer="Random"
|
2022-02-18 20:35:11 +01:00
|
|
|
elif [[ "$RNUM" == "2" ]]; then
|
2022-02-20 09:12:17 +01:00
|
|
|
answer="Twisted"
|
2022-02-18 20:35:11 +01:00
|
|
|
get_random_number "500"
|
|
|
|
twist="$RNUM"
|
|
|
|
else
|
|
|
|
answer="c"
|
|
|
|
get_random_color
|
|
|
|
color="$RCOLOR"
|
|
|
|
fi
|
|
|
|
else
|
2022-02-20 09:12:17 +01:00
|
|
|
answer=$(yad --title='Choose Style' --width=190 --height=150 --button=Ok:0 --list --no-headers --column=Style Random Twisted 'Custom colors' | tr -d '|')
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
name="plasma_$name"
|
2022-02-20 09:12:17 +01:00
|
|
|
if [[ $answer == "r" ]] || [[ $answer == "Random" ]]; then
|
2022-02-18 20:35:11 +01:00
|
|
|
convert -size "$size" plasma: "$DIR/$name"
|
2022-02-20 09:12:17 +01:00
|
|
|
elif [[ $answer == "t" ]] || [[ $answer == "Twisted" ]]; then
|
2022-02-18 20:35:11 +01:00
|
|
|
if [[ "$RANDOMIZE" != "true" ]]; then
|
2022-02-20 09:12:17 +01:00
|
|
|
twist=$(yad --center --window-icon=mbcc --title="Plasma" --text="\tTwisting amount (default is 150):" --width=400 --scale --value=150 --min-value=0 --max-value=500 --step=20 --inc-buttons)
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
convert -size "$size" plasma:fractal -swirl "${twist:-150}" "$DIR/$name"
|
|
|
|
else
|
|
|
|
if [[ "$RANDOMIZE" != "true" ]]; then
|
2022-02-20 09:12:17 +01:00
|
|
|
get_color
|
2022-02-18 20:35:11 +01:00
|
|
|
fi
|
|
|
|
convert -size "$size" plasma:"$color" "$DIR/$name"
|
|
|
|
fi
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate a random, multi-colored blurred/gradient wallpaper
|
|
|
|
blurred_noise() {
|
|
|
|
if [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
get_random_number "30"
|
|
|
|
blur="$RNUM"
|
|
|
|
else
|
|
|
|
{ echo; read -p ${ORANGE}"Enter the blur strength (maximum 30): "${BLUE} blur; }
|
|
|
|
fi
|
|
|
|
convert -size "100x56" xc: +noise Random "/tmp/noise.png"
|
|
|
|
convert "/tmp/noise.png" -virtual-pixel tile -blur 0x"${blur:-14}" -auto-level -resize "$size" "$DIR/$name"
|
|
|
|
set_bg
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate random number lower than giver parameter
|
|
|
|
get_random_number() {
|
|
|
|
RNUM=$(( ($RANDOM % $1) + 1 ))
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate random color
|
|
|
|
get_random_color() {
|
|
|
|
RCOLOR="#"
|
|
|
|
for i in 1 2 3 4 5 6
|
|
|
|
do
|
|
|
|
get_random_number "16"
|
|
|
|
case $RNUM in
|
|
|
|
"1") NEXTDIGIT="1";;
|
|
|
|
"2") NEXTDIGIT="2";;
|
|
|
|
"3") NEXTDIGIT="3";;
|
|
|
|
"4") NEXTDIGIT="4";;
|
|
|
|
"5") NEXTDIGIT="5";;
|
|
|
|
"6") NEXTDIGIT="6";;
|
|
|
|
"7") NEXTDIGIT="7";;
|
|
|
|
"8") NEXTDIGIT="8";;
|
|
|
|
"9") NEXTDIGIT="9";;
|
|
|
|
"10") NEXTDIGIT="A";;
|
|
|
|
"11") NEXTDIGIT="B";;
|
|
|
|
"12") NEXTDIGIT="C";;
|
|
|
|
"13") NEXTDIGIT="D";;
|
|
|
|
"14") NEXTDIGIT="E";;
|
|
|
|
"15") NEXTDIGIT="F";;
|
|
|
|
"16") NEXTDIGIT="0";;
|
|
|
|
esac
|
|
|
|
RCOLOR="$RCOLOR$NEXTDIGIT"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate random shape option
|
|
|
|
getRandomShape() {
|
|
|
|
get_random_number "4"
|
|
|
|
case $RNUM in
|
|
|
|
"1") RSHAPE="diagonal";;
|
|
|
|
"2") RSHAPE="ellipse";;
|
|
|
|
"3") RSHAPE="maximum";;
|
|
|
|
"4") RSHAPE="minimum";;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
## Generate random wallpaper
|
|
|
|
randomize() {
|
|
|
|
get_random_number "7"
|
|
|
|
case $RNUM in
|
|
|
|
"1") solid;;
|
|
|
|
"2") linear_gradient;;
|
|
|
|
"3") radial_gradient;;
|
|
|
|
"4") twisted_gradient;;
|
|
|
|
"5") bilinear_gradient;;
|
|
|
|
"6") plasma;;
|
|
|
|
"7") blurred_noise;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
## Parse the arguments
|
2022-02-20 09:12:17 +01:00
|
|
|
options=$(getopt -o S:,s,l,r,t,b,p,B,h,a,R --long size:,solid,linear,radial,twisted,bilinear,plasma,blurred,help,autobg,randomize -- "$@")
|
2022-02-18 20:35:11 +01:00
|
|
|
eval set -- "$options"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-S|--size)
|
|
|
|
shift;
|
|
|
|
size=$1
|
|
|
|
;;
|
|
|
|
-s|--solid)
|
|
|
|
SOLID="true"
|
|
|
|
COLOR=$1
|
|
|
|
;;
|
|
|
|
-l|--linear)
|
|
|
|
GRADIENT="true"
|
|
|
|
;;
|
|
|
|
-r|--radial)
|
|
|
|
RGRADIENT="true"
|
|
|
|
;;
|
|
|
|
-t|--twisted)
|
|
|
|
TGRADIENT="true"
|
|
|
|
;;
|
|
|
|
-b|--bilinear)
|
|
|
|
BGRADIENT="true"
|
|
|
|
;;
|
|
|
|
-p|--plasma)
|
|
|
|
PLASMA="true"
|
|
|
|
;;
|
|
|
|
-B|--blurred)
|
|
|
|
NOISE="true"
|
|
|
|
;;
|
|
|
|
-a|--autobg)
|
|
|
|
AUTOBG="true"
|
|
|
|
;;
|
|
|
|
-R|--randomize)
|
|
|
|
RANDOMIZE="true"
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
## Main Execution
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$SOLID" == "true" ]]; then
|
|
|
|
solid
|
|
|
|
elif [[ "$GRADIENT" == "true" ]]; then
|
|
|
|
linear_gradient
|
|
|
|
elif [[ "$RGRADIENT" == "true" ]]; then
|
|
|
|
radial_gradient
|
|
|
|
elif [[ "$TGRADIENT" == "true" ]]; then
|
|
|
|
twisted_gradient
|
|
|
|
elif [[ "$BGRADIENT" == "true" ]]; then
|
|
|
|
bilinear_gradient
|
|
|
|
elif [[ "$PLASMA" == "true" ]]; then
|
|
|
|
plasma
|
|
|
|
elif [[ "$NOISE" == "true" ]]; then
|
|
|
|
blurred_noise
|
|
|
|
elif [[ "$RANDOMIZE" == "true" ]]; then
|
|
|
|
randomize
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|