JPEG optimization tools benchmark


I have a web project that hosts more than 15.000 images of various sizes from 300kb up to 10MB.
In total these images take about 8GB of space. These images are served from a small VPS with 365MB of RAM and optimized LAMP stack with Nginx as reverse proxy.
Since I am a performance freak, I want to speed up the image serving as much as possible.
But before tweaking any server settings I have to optimize the images themselves.
For this I started looking for linux JPEG optimization tools and found a few, no idea which one is the best so I decided to run a few benchmarks and share the results with the rest of you.

List of tools

jpegrescan - A lossless jpeg optimization script written in Perl. Created in 2008 and hosted for a long time on a pastebin page it doesn't inspire a lot of confidence, but why not.

jpegtran - A popular tool for lossless jpeg optimization.

JPGCrush - Found only as a comment on hacker news without any documentation or info. Lets do this!

jpegoptim - Maybe the most popular tool for lossless and lossy image optimization

imgopt - A rather simple bash script that uses multiple tools at the same time to achieve maximum optimization.


For the benchmark I am going to use the following:
4 random images from /r/serverporn.
My own image collection of 872808kb.

First I am going to test the 4 random images

Name Type Parameters Total size before (KB) Total size after (KB) Difference
jpegrescan lossless none 3772 3556 -5.726%
jpegtran lossless -copy none -optimize 3772 3724 -1.273%
jpegtran lossless -copy none -optimize -progressive 3772 3560 -5.62%
JPGCrush lossless none 3772 3772 0% *
jpegoptim lossless --strip-all 3772 3724 -1.273%
jpegoptim lossly --strip-all --max=90 3772 3236 -14.21%
imgopt lossless none 3772 3724 -1.273%
*Not sure where is the problem. It run just fine with no results. I will be excluding it from the next benchmark.

And now some heavy testing. I have a directory with 2400 images and a total size of 853MB.
Lets see how the tools are doing on a larger scale.

Name Type Parameters Total size before (KB) Total size after (KB) Difference
jpegrescan lossless none 872808 756976 -13.271%
jpegtran lossless -copy none -optimize 872808 797764 -8.598
jpegtran lossless -copy none -optimize -progressive 872808 770764 -11.691%
jpegoptim lossless --strip-all 872808 819896 -6.062%
jpegoptim lossy --strip-all --max=90 872808 606260 -30.539%
imgopt lossless none 872808 832072 -4.667%


I didn't expect this, jpegrescan has the best lossless compression compared to all other tools including the most popular ones. Of course it took about 4-5 times longer to finish, but still, who knew.
And of course the winner is jpegoptim with lossy compression and quality of 90.
I think this the best option, since the users can not tell the difference between 100 and a 90 quality but the size reduction is significant.