diff --git a/bin/chbg b/bin/chbg index 25e1ece..5404393 100755 --- a/bin/chbg +++ b/bin/chbg @@ -1,24 +1,33 @@ #!/bin/bash # to change wallpapers both niri workspace and niri tab view -[ -z "$1" ] && { echo "Usage: $0 "; exit 1; } - -WP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}" -TMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}" -finput=$1 - -read -r fw fh < <(magick identify -format "%w %h" -- "$1") -(( fw > 3840 && fh > 2160 )) && { - mkdir -p $TMP_DIR - finput="$TMP_DIR/${finput##*/}" - echo "WARNING: image too large, resizing ..." - magick $1 -resize "3840x2160^" $finput +[ -z "$1" ] && { + echo "Usage: ${0##*/} " + exit 1 +} +fsize=$(magick identify -format "%w %h" -- "$1" 2>/dev/null) || { + echo "ERROR: unable to identify. is it an EXISTING ACCESSIBLE IMAGE file?" + exit 1 } -echo -n "making blurred version of $finput ... " +WP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}" +finput=$1 + +read -r fw fh <<< "$fsize" +(( fw > 3840 && fh > 2160 )) && { + finput="$(mktemp --dry-run).webp" + trap 'rm -f "$finput"' EXIT + echo "WARNING: image too large, resizing ..." + # echo "DEBUG: resized image at $finput" + magick "$1" -resize "3840x2160^" \ + -quality 90 \ + -define webp:method=6 \ + -define webp:alpha-quality=100 "$finput" +} + +echo -n "making blurred version of ${1##*/} ... " mkdir -p $WP_DIR cp $finput $WP_DIR/.wallpaper magick $WP_DIR/.wallpaper -filter Gaussian -blur 0x30 $WP_DIR/.wallpaper_blur -[[ $finput == $TMP_DIR* ]] && rm -f $finput echo "Done." swww img $WP_DIR/.wallpaper