sudo apt update && apt install jpegoptim optipng -y
Install dependencies
sudo apt-get install build-essential libpng-dev -y
compile optipng
cd /usr/local/src
OPTIPNGLATEST=$(wget http://optipng.sourceforge.net/ -qO - | grep tar.gz | awk -F "[\"]" '{print $4}')
wget $OPTIPNGLATEST -qO optipng.tar.gz
tar -xf optipng.tar.gz
cd optipng-*
If gcc8.1 available :
export CC="/usr/bin/gcc-8"
export CXX="/usr/bin/gc++-8"
If gcc7 available :
export CC="/usr/bin/gcc-7"
export CXX="/usr/bin/gc++-7"
Compile optipng
./configure --prefix=/usr
make -j "$(nproc)"
sudo make install
cd /path/to/your/image/folder
find . -iname "*.jp*" -print0 | xargs -0 jpegoptim --strip-all -m76
cd /path/to/your/image/folder
find . -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve