diff --git a/cron/optimize-cron.sh b/cron/optimize-cron.sh new file mode 100644 index 0000000..12f9a80 --- /dev/null +++ b/cron/optimize-cron.sh @@ -0,0 +1,20 @@ +input="sites.csv" +while IFS='|' read -r f1 f2 +do + imagepath="$f2" + # optimize jpg images created in the last 24 hours + find $imagepath -iname "*.jp*" -ctime 0 -print0 | xargs -0 jpegoptim --quiet --strip-all -m76 + # optimize png images created in the last 24 hours + find $imagepath -iname '*.png' -ctime 0 -print0 | xargs -0 optipng -o7 -quiet -preserve + # convert png to webp + find $imagepath -iname "*.png" -ctime 0 -print0 | xargs -0 -I {} \ + bash -c 'webp_version="$0".webp + if [ ! -f "$webp_version" ]; then + { cwebp -quiet -lossless {} -o {}.webp; } + fi' + find $imagepath -iname "*.jp*" -ctime 0 -print0 | xargs -0 -I {} \ + bash -c 'webp_version="$0".webp + if [ ! -f "$webp_version" ]; then + { cwebp -quiet -lossless {} -o {}.webp; } + fi' +done < "$input" \ No newline at end of file diff --git a/cron/sites.csv b/cron/sites.csv new file mode 100644 index 0000000..c0421ae --- /dev/null +++ b/cron/sites.csv @@ -0,0 +1,2 @@ +1|/var/www/yoursite.tld/htdocs/wp-content/uploads +2|/var/www/yourothersite.tld/htdocs/wp-content/uploads \ No newline at end of file diff --git a/install-optipng.sh b/install-optipng.sh new file mode 100644 index 0000000..d02e4ac --- /dev/null +++ b/install-optipng.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +sudo apt-get install build-essential libpng-dev -y + +cd /usr/local/src + +OPTIPNGLATEST=$(wget http://optipng.sourceforge.net/ -O - | grep tar.gz | awk -F "[\"]" '{print $4}') +wget $OPTIPNGLATEST -O optipng.tar.gz +tar -xf optipng.tar.gz +cd optipng-* +./configure --prefix=/usr +make -j "$(nproc)" +sudo make install \ No newline at end of file diff --git a/optimize.sh b/optimize.sh index d110ab8..43490b2 100644 --- a/optimize.sh +++ b/optimize.sh @@ -46,8 +46,7 @@ find $imagepath -iname '*.png' -print0 | xargs -0 optipng -o7 -quiet -preserve # convert png to webp webpconvert() { find $imagepath -iname "*.png" -print0 | xargs -0 -I {} \ -bash -c ' -webp_version="$0".webp +bash -c 'webp_version="$0".webp if [ ! -f "$webp_version" ]; then { cwebp -quiet -lossless {} -o {}.webp; } fi' @@ -57,9 +56,7 @@ fi' # convert jpg to webp find $imagepath -iname "*.jp*" -print0 | xargs -0 -I {} \ -bash -c ' -webp_version="$0".webp - +bash -c 'webp_version="$0".webp if [ ! -f "$webp_version" ]; then { cwebp -quiet -lossless {} -o {}.webp; } fi'