[HOWTO] Lossless image optimization of all VestaCP sites
Posted: Thu Dec 28, 2017 4:14 pm
If you are looking for a way to losslessly optimize all JPG and PNG images of your sites hosted with VestaCP, search no more.
This is great because you will:
Install jpegoptim and optipng
CentOS
Ubuntu
Now run this simple scripts which will do all the job for you.
(You may want to run above again just replace *.jpg with *.jpeg
I recommend running this inside a screen especially if you have a lot of sites.
If you do not know what screen is.
The script always runs as the user owning the file, file ownership will remain correct. Also it's 100% safe to use.
This is great because you will:
- Decrease disk usage
- Optimize page loading time
- Improve SEO
Install jpegoptim and optipng
CentOS
Code: Select all
yum install jpegoptim optipng -y
Code: Select all
sudo apt-get install jpegoptim optipng -y
Code: Select all
for i in `/usr/local/vesta/bin/v-list-sys-users | awk '{if(NR>2)print}'`; do find /home/$i/web/ -name 'public_html' -type d -print0 | xargs -0 -I {} find {} -iname '*.jpg' -type f -print0 | xargs -0 -I {} sudo -H -u $i jpegoptim --strip-all {}; done
Code: Select all
for i in `/usr/local/vesta/bin/v-list-sys-users | awk '{if(NR>2)print}'`; do find /home/$i/web/ -name 'public_html' -type d -print0 | xargs -0 -I {} find {} -iname '*.png' -type f -print0 | xargs -0 -I {} sudo -H -u$i optipng {}; done
If you do not know what screen is.
The script always runs as the user owning the file, file ownership will remain correct. Also it's 100% safe to use.