From fc71c053275893c448677246bec754e036c5ac24 Mon Sep 17 00:00:00 2001 From: Lee Cattarin Date: Thu, 19 Feb 2026 21:12:50 -0800 Subject: [PATCH] let's keep good ol mogrify around --- mogrify.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 mogrify.sh diff --git a/mogrify.sh b/mogrify.sh new file mode 100755 index 0000000..272fbc3 --- /dev/null +++ b/mogrify.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# check for mogrify +which mogrify > /dev/null +if [[ $? -ne 0 ]] +then + echo "mogrify not found, run the following:" + echo "sudo apt install imagemagick" + exit 1 +fi + +# finds pattern [number]x[number] +REGEX="([0-9]+)x[0-9]+" +MAX_WIDTH=1200 + +for FILE in $(find src/img) +do + # skip directories + if [ -d $FILE ] + then + continue + fi + + # `identify` prints out file info incl. dimensions in pixels + if [[ $(identify $FILE) =~ $REGEX ]] + then + # regex capture groups + WIDTH=${BASH_REMATCH[1]} + + # resize if too large + if (( $WIDTH > $MAX_WIDTH )) + then + echo "resizing $FILE with width $WIDTH" + mogrify -resize 1200x $FILE + fi + fi +done