[TASK] Convert images to webp if cwebp is available
This commit is contained in:
+13
-2
@@ -4,7 +4,7 @@ DIR="/home/immortaly007/screenshot-log"
|
|||||||
FORMAT="png"
|
FORMAT="png"
|
||||||
SIMILARITY_DELETE_TRESHOLD=100
|
SIMILARITY_DELETE_TRESHOLD=100
|
||||||
HTML_THUMB_WIDTH=200
|
HTML_THUMB_WIDTH=200
|
||||||
SCALE="50%"
|
SCALE="75%"
|
||||||
# Max time (in seconds) to wait before forcing a screenshot even if spectacle is running
|
# Max time (in seconds) to wait before forcing a screenshot even if spectacle is running
|
||||||
SPECTACLE_BLOCKED_TIMEOUT=600 # 10 minutes
|
SPECTACLE_BLOCKED_TIMEOUT=600 # 10 minutes
|
||||||
|
|
||||||
@@ -66,9 +66,20 @@ then
|
|||||||
echo "`date`: Distance = $DISTANCE; too similar; RM $SCR_NEW"
|
echo "`date`: Distance = $DISTANCE; too similar; RM $SCR_NEW"
|
||||||
# echo "`date` RM" >> $DIR/$DAY/log-.log
|
# echo "`date` RM" >> $DIR/$DAY/log-.log
|
||||||
else
|
else
|
||||||
|
# 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
|
mogrify -scale $SCALE $SCR_LAST
|
||||||
|
fi
|
||||||
# Ensure that the new file is still seen as the most recent one
|
# Ensure that the new file is still seen as the most recent one
|
||||||
FUTURE=`date +%Y%m%d%H%M.%S -d "+1 second"`
|
FUTURE=`date +%Y%m%d%H%M.%S -d "+1 second"`
|
||||||
touch -t $FUTURE "$SCR_NEW"
|
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
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user