From cb0605971df92d9909473f1523e9ae7d688d614a Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 7 Jan 2023 14:50:34 +0100 Subject: [PATCH] scripts: Add wallcrop.sh Added hacky script to quickly cut apart dual-screen wallpapers. I run two 1920x1080 screens side-by-side, so I just cut double wide wallpapers in two and display one on each screen. Script is very inflexible on probably not too useful for the future but it works for its purposes now. --- scripts/.local/bin/wallcrop.sh | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 scripts/.local/bin/wallcrop.sh diff --git a/scripts/.local/bin/wallcrop.sh b/scripts/.local/bin/wallcrop.sh new file mode 100755 index 0000000..9155dd8 --- /dev/null +++ b/scripts/.local/bin/wallcrop.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# A simple script to make it easy for me to crop newly found wallpapers +# to size, for one 1920x1080 screen on the left and one on the right. +# The resulting images can be used with wallpaper programs (e.g. swww) +# to nicely display per monitor without stretching. +# +# Usage: wallcrop.sh path/to/my/imagefile.jpg +# It will drop two cut versions in the same directory and tell you where +# they are. + +# TODO check image dimensions and warn user if not 3840x1080, or at least if smaller than cropped area + +main() { + fullname="$1" + filename=$(basename -- "$fullname") + pathonly=${fullname/$filename/} + extension="${filename##*.}" + filename="${filename%.*}" + + out_left="${pathonly}${filename}_l.$extension" + out_right="${pathonly}${filename}_r.$extension" + + printf "input: %s\noutput left:%s\noutput right: %s\n" "$fullname" "$out_left" "$out_right" + gm convert "$fullname" -crop 1920x1080+0+0 "$out_left" + gm convert "$fullname" -crop 1920x1080+1920+0 "$out_right" +} + +usage="$(basename "$0") [-h] path/to/my/imagefile.jpg -- Simple image cropper for dual screen 1920x1080 setups. + +A simple script to make it easy for me to crop newly found wallpapers +to size, for one 1920x1080 screen on the left and one on the right. +The resulting images can be used with wallpaper programs (e.g. swww) +to nicely display per monitor without stretching. + + -h show this help text + +It will drop two cut versions in the same directory and tell you where +they are." + +while getopts ':h' option; do + case "$option" in + h) + echo "$usage" + exit + ;; + :) + printf "missing argument for -%s\n" "$OPTARG" >&2 + echo "$usage" >&2 + exit 1 + ;; + \?) + printf "illegal option: -%s\n" "$OPTARG" >&2 + echo "$usage" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ "$#" -ne 1 ]; then + echo "$usage" >&2 + exit 1 +fi +main "$1"