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


Messages In This Thread
Optimize Images for Faster Loading - Ubuntu - by pinguy - 03-04-2016, 11:59 AM

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

Forum Jump:


Users browsing this thread: 1 Guest(s)