[TASK] Convert images to webp if cwebp is available

This commit is contained in:
2026-04-01 14:58:12 +02:00
parent 3e9e0e8a0e
commit 367dcbf737
+14 -3
View File
@@ -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 "<p>`date +%H:%M:%S` <a href=\"$SCR_NEW\"><img width=\"$HTML_THUMB_WIDTH\" src=\"$SCR_NEW\" /></a> <br />$WINDOW_TITLE </p>" >> $DIR/`date +%Y-%m-%d`-$PREFIX.html
fi