Lossless image optimization — even for JPG!
As you may know, I run an arcade site. It is doing fairly well, but I’m always looking for ways to gain an edge that will put me ahead of the competition.
The most recent thing I am trying is image optimization. With the announcement by Google that they are adding site speed to their page ranking equation, it is more important than ever to have a fast site.
I get all my games and game thumbnails from Mochi, a free source for Flash games. I’ve written code to do this all automatically for me. The problem is, some game authors think it is okay to include a 200KB thumbnail (they are only 100x100px!). Alone this might not be the end of the world, but when you get a page of 50 thumbnails and each is 60KB to 200KB, then you have a problem.
The solution? Image optimization!
It is important to note that image optimization is not image compression. Compression generally results in degraded image quality. Optimization programs take the image file that already exists, and re-organizes the data in the image file so that the end result is the same, but it takes up less space. Optimization programs sometimes also remove data that isn’t relevant to the display of the image, like unused colors in a GIF color palette or EXIF data in a JPG.
I had a really hard time finding a JPG optimization program that didn’t reduce the quality of the picture, but finally found a 5 year old package that does the job great: littleutils. Note: The download link on that page is wrong, try this one instead.
This collection of little utilities includes 3 great image optimizers for Linux: opt-png, opt-jpg, opt-gif. These items do a brute-force style optimization of the image, trying many methods until it finds the method that produces the smallest file size for each individual image. Even though these tools are 5 years old, the opt-png utility produced smaller file sizes than the popular pngcrush and pngout utilities, and the punypng web service. Amazing!
By using these tools, I reduced the file size of my thumbnails by an average of 35%! That is a huge difference, and will make a huge difference to my visitors.
I’ve also updated my automated game downloading script to tie into these utilities, so the optimization happens without me having to ever touch it.
If you need help installing these utilities, let me know. There were a lot of optional dependencies that made a huge difference in the size of the optimized files, so make sure you install all of them before compiling littleutils.