From 367dcbf7376971aa340ee4e1b897d2647e3f4631 Mon Sep 17 00:00:00 2001 From: Bas Dado Date: Wed, 1 Apr 2026 14:58:12 +0200 Subject: [PATCH] [TASK] Convert images to webp if cwebp is available --- screenshot.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/screenshot.sh b/screenshot.sh index 0a56f83..95da5f4 100755 --- a/screenshot.sh +++ b/screenshot.sh @@ -4,7 +4,7 @@ DIR="/home/immortaly007/screenshot-log" FORMAT="png" SIMILARITY_DELETE_TRESHOLD=100 HTML_THUMB_WIDTH=200 -SCALE="50%" +SCALE="75%" # Max time (in seconds) to wait before forcing a screenshot even if spectacle is running SPECTACLE_BLOCKED_TIMEOUT=600 # 10 minutes @@ -66,9 +66,20 @@ then echo "`date`: Distance = $DISTANCE; too similar; RM $SCR_NEW" # echo "`date` RM" >> $DIR/$DAY/log-.log else - mogrify -scale $SCALE $SCR_LAST + # If cwebp is available, convert the new screenshot to webp format and delete the original png + if command -v cwebp > /dev/null; then + WIDTH=$(identify -format "%w" $SCR_NEW) + TARGET_WIDTH=$(( WIDTH * ${SCALE%%%} / 100 )) + echo "Converting $SCR_NEW to webp format with target width $TARGET_WIDTH" + # I tried some different cwebp options (-preset text/picture), -m 6), but default seems to give the best results especially given runtime. + cwebp -quiet -resize $TARGET_WIDTH 0 $SCR_NEW -o "${SCR_NEW%.png}.webp" + rm $SCR_NEW + SCR_NEW="${SCR_NEW%.png}.webp" + else + # If cwebp is not available, we can still reduce the size of the png by resizing it with mogrify + mogrify -scale $SCALE $SCR_LAST + fi # Ensure that the new file is still seen as the most recent one FUTURE=`date +%Y%m%d%H%M.%S -d "+1 second"` touch -t $FUTURE "$SCR_NEW" -# echo "

`date +%H:%M:%S`
$WINDOW_TITLE

" >> $DIR/`date +%Y-%m-%d`-$PREFIX.html fi