MaxLazar
1/23/2015 - 2:00 AM

Image optimization

Image optimization

#!/bin/sh
declare -a iPath=('/var/www/vhosts/public_html/images/misc');
lof_file=('/var/www/vhosts/image_opt.log')

start_time=$(date +%s)

if [ -f $lof_file ];
then
    dt_mod=("-newer $lof_file")
else
    dt_mod=""
fi
#dt_mod=("-mtime +2")

for i in "${iPath[@]}"
do
    find $i  -iname "*.j*g" $dt_mod -type f -print0 | xargs -0 mogrify -resize 1920x1920\> -quality 90
    find $i  -iname "*.j*g" $dt_mod -type f -print0 | xargs -0 jpegoptim --strip-all
    find $i  -iname "*.png" $dt_mod -type f -print0 | xargs -0 optipng -o7
    find $i  -iname "*.gif" $dt_mod -type f -print0 | xargs -0 gifsicle -b -O3 --careful
    #chmod -R rgritton.psacln $i
done

end_time=$(date +%s)

duration=$(($end_time-$start_time))

echo "$(date +%Y-%m-%d-%H-%M-%S) : duration = $duration" >> $lof_file