Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section Modification & Patches
  • Search
Reminder: On the servers affected by ChachaDDoS passwords for admin and root need to be changed necessarily

[HOWTO] Lossless image optimization of all VestaCP sites Topic is solved

Section with modification and patches for Vesta
Post Reply
  • Print view
Advanced search
3 posts • Page 1 of 1
lukapaunovic
Posts: 72
Joined: Sun Dec 03, 2017 6:30 pm

[HOWTO] Lossless image optimization of all VestaCP sites
  • Quote

Post by lukapaunovic » 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:
  1. Decrease disk usage
  2. Optimize page loading time
  3. Improve SEO
So let's begin.

Install jpegoptim and optipng

CentOS

Code: Select all

yum install jpegoptim optipng -y
Ubuntu

Code: Select all

sudo apt-get install jpegoptim optipng -y
Now run this simple scripts which will do all the job for you.

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
(You may want to run above again just replace *.jpg with *.jpeg

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
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.
Top

moh3n
Posts: 10
Joined: Sun Nov 27, 2016 8:31 am

Os: CentOS 7x
Web: apache + nginx
Re: [HOWTO] Lossless image optimization of all VestaCP sites
  • Quote

Post by moh3n » Thu Apr 26, 2018 6:03 am

does this need to run every time after adding new images?
is there any way to add this to cron to run it rapidly?
Top

lukapaunovic
Posts: 72
Joined: Sun Dec 03, 2017 6:30 pm

Re: [HOWTO] Lossless image optimization of all VestaCP sites
  • Quote

Post by lukapaunovic » Tue May 01, 2018 7:58 pm

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:

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 chmod +x /home/cron.sh

Then add to crontab -e

Code: Select all

0 0 * * * /usr/bin/bash /home/images.sh
Top


Post Reply
  • Print view

3 posts • Page 1 of 1

Return to “Modification & Patches”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password