Optimize jpg images on server

November 12, 2017 at 5:27 pm

Optimizing images on server is pretty important thing.
Not only this reduces images file size, but also speeds up page loading time.
Every website optimization tool including Page Speed Insights by Google will suggest to optimize images if they are not.


Over 90% of image files on server are of JPEG type.
There are several tools that allow to optimize JPEG image for web use and possibly most popular is JPEGTRAN that you can download free from http://jpegclub.org/jpegtran/ .

You need to install it on server (must have server’s ROOT access)
Here’s quick guide how to install it:

Easy way:

yum install libjpeg*

From source:

cd /usr/local/src
wget http://jpegclub.org/jpegcrop.tar.gz
tar -zxf jpegcrop.tar.gz
cd jpegcrop/jpeg-*
make install

You can check if JPEGTRAN is installe:

which jpegtran


yum install libjpeg-turbo-utils


sudo apt-get install jpegoptim


Now quick guide how to optimize all “jpg” image files on your server for your website using simple SSH command.
First you must navigate to your website “public_html” directory, eg.

cd /home/domain/public_html

Location of public_html folder can be different, depending on system installed.

And finally you can enter command to optimize all jpg files

find -name "*.jpg" -type f -exec jpegtran -copy none -optimize -outfile {} {} \;

This can take some time if you have thousands of jpg image files on server.
Best is to use such command as CRON job, for example once per few days or even everyday at midnight.