We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
[HOWTO] Lossless image optimization of all VestaCP sites Topic is solved
-
- Posts: 73
- Joined: Sun Dec 03, 2017 6:30 pm
[HOWTO] Lossless image optimization of all VestaCP sites
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.
Re: [HOWTO] Lossless image optimization of all VestaCP sites
does this need to run every time after adding new images?
is there any way to add this to cron to run it rapidly?
is there any way to add this to cron to run it rapidly?
-
- Posts: 73
- Joined: Sun Dec 03, 2017 6:30 pm
Re: [HOWTO] Lossless image optimization of all VestaCP sites
Yes, it could be added to cron. But the only flaw here is that when you run it again it will go through all already optimized images, it will detect they are optimized but that loses a lot of time.
Here is an example of a cron
create /home/images.sh with content:
Then chmod +x /home/cron.sh
Then add to crontab -e
Here is an example of a cron
create /home/images.sh with content:
Code: Select all
VESTA=/usr/local/vesta
export VESTA
PATH=$PATH:/usr/local/vesta/bin
export PATH
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
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
Then add to crontab -e
Code: Select all
0 0 * * * /usr/bin/bash /home/images.sh