This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Optimize Images for Faster Loading - Ubuntu
#1
Optimize Images for Faster Loading - Ubuntu
To optimize all the images in the public_html folder once a month. Run this:

Code:
apt-get install jpegoptim optipng

Code:
nano /etc/cron.monthly/optimgs

Code:
#!/bin/bash
cd /var/sentora/hostdata/zadmin/public_html
find -iregex '.*\.\(png\)$' -print0 | xargs -0 optipng -o7 -preserve
find -iregex '.*\.\(jpg\|jpeg\)$' -print0 | xargs -0 jpegoptim --max=90 --strip-all –all-progressive --preserve --totals
find -iregex '.*\.\(jpg\|png\|jpeg\)$' -exec chmod 644 {} \;
find -iregex '.*\.\(jpg\|png\|jpeg\)$' -exec chown www-data:www-data {} \;
exit 0

F3 will save the file and Ctrl+X will exit nano.

Code:
sudo chmod +x '/etc/cron.monthly/optimgs'
sudo chmod 755 '/etc/cron.monthly/optimgs'

A bit of a warning. OptiPNG is very slow. May take a few hours to complete if you have a large amount of .pngs
Reply
Thanks given by: Bobses
#2
RE: Optimize Images for Faster Loading - Ubuntu
This cron will use a lot of CPU so better if you downgrade priority using NICE

http://askubuntu.com/questions/48708/cha...ng-process
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask

200$ free to start your VPS 60 days credit
Reply
Thanks given by:
#3
RE: Optimize Images for Faster Loading - Ubuntu
this is just for zadmin?

also is there a method to manually start or say on a specific time and date?
Reply
Thanks given by:
#4
RE: Optimize Images for Faster Loading - Ubuntu
(03-13-2016, 11:33 AM)warmax356 Wrote: this is just for zadmin?

This is for Sentora.

(03-13-2016, 11:33 AM)warmax356 Wrote: also is there a method to manually start or say on a specific time and date?

It's just a cron job. You can create a cron job to run when ever you like.
http://www.cyberciti.biz/faq/how-do-i-ad...unix-oses/
Reply
Thanks given by:
#5
RE: Optimize Images for Faster Loading - Ubuntu
(03-04-2016, 10:46 PM)Me.B Wrote: This cron will use a lot of CPU so better if you downgrade priority using NICE

http://askubuntu.com/questions/48708/cha...ng-process

Been running this for awhile now. It really doesn't use that much CPU. Did a load test to see how much it effected the server, and it doesn't slow down the site at all.
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
Upgrade to Ubuntu 16.04 from 14.04 HogensHero 8 30 ,227 07-18-2020, 03:13 AM
Last Post: dycott78
Ubuntu: How to Enable tls/ssl in proftpd Diablo925 2 12 ,799 04-21-2020, 03:35 AM
Last Post: iraqiboy90
Ubuntu 18.04 or 20.04 Kangarooo 1 6 ,927 03-20-2020, 11:39 AM
Last Post: Jettaman

Forum Jump:


Users browsing this thread: 2 Guest(s)