diff options
author | xyz <gky44px1999@gmail.com> | 2021-08-11 03:53:26 -0700 |
---|---|---|
committer | xyz <gky44px1999@gmail.com> | 2021-08-11 03:53:26 -0700 |
commit | b804d8ebfe38e7559e26d7df05d3fbf87c9652a3 (patch) | |
tree | 84f17a18f11c08ee51f9ea7e29c685e11b64035c | |
parent | cf835322a23fa25b5f8f69ef9f62e7a611d8f0dd (diff) |
convert wallpaper script
-rwxr-xr-x | .local/bin/convwall | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/.local/bin/convwall b/.local/bin/convwall new file mode 100755 index 00000000..326a3de9 --- /dev/null +++ b/.local/bin/convwall @@ -0,0 +1,27 @@ +#!/bin/sh + +# 16:9 screen resolution ratio +wratio=16 +hratio=9 +chopnum=99% + +width=$(identify -format '%w' "$1") +height=$(identify -format '%h' "$1") + +dim=$(echo "$width*100/$height" | bc) + +if [ "$dim" -ne 177 ]; then + if [ "$dim" -lt 177 ]; then + chopgeom="${chopnum}x0" + width=$(echo "$height*$wratio/$hratio" | bc) + else + chopgeom="0x${chopnum}" + height=$(echo "$width*$hratio/$wratio" | bc) + fi + extgeom="${width}x${height}" + bgcolor=$(convert "$1" -gravity center -chop "$chopgeom" -define histogram:unique-colors=true -format %c histogram:info:- | sort -rn | head -n1 | awk \{print\ \$3\} | cut -c1-7) + convert "$1" -gravity center -background "$bgcolor" -extent "$extgeom" "$2" +else + echo 'same resolution ratio, no need to convert' >&2 + exit 1 +fi |