Google Page Speed offers several lossless image compression tools for JPEG and PNG files. Jpegtran or jpegoptim are recommended for jpeg, and OptiPNG or PNGOUT are recommended for png. Install these packages: Debian/Ubuntu
apt-get install jpegoptim optipng
CentOS/RedHat
yum install jpegoptim optipng
Using the command for recursive optimization of images on the server, enter the user who is the owner and execute the commands:
For PNG
find ./ -type f -iname "*.png" -exec optipng -strip all -o4 {} \;
For JPG
find ./ -type f -iname "*.jpg" -exec jpegoptim --strip-all --all-progressive -pm85 {} \; -exec chmod 644 {} \;
optipng and jpegoptim are rarely seen on a virtual hosting, then you can use convert, a command that performs a change in the size and quality of the image:
find ./ -iregex '.*.jpg' -exec convert '{}' -resize 80% -quality 50 jpg:'{}' \;