Optimization of PNG and JEPG images, using two different utilities first one is jpegoptim which is used to optimize JEPG images to use it recursively and optimize all of images in directory and sub directory you can use this command:
find . -name "*.jpg" | xargs jpegoptim --strip-all --all-progressive
This will strip all data and make images progressive.
PNG images can be optimized with Optipng
find . -name *.png | xargs optipng -nc -nb -o7 -full