Stephen Bay's Photography Blog

How to Minimize Jpeg File Size for a Photo Website

If you have a photography website, you’re probably aware that the biggest obstacle to obtaining quick page load times is the size of your image files. You want to use large hi-resolution photos with low compression to present your images at their best. But inevitably this means large file sizes which load slowly. Slow loading files annoys users and makes them more likely to give up and browse some other site instead.

Thankfully there are some very smart people that have worked on this and there are a number of free and paid programs that will take output jpegs from Lightroom or Photoshop and compress them even more without losing image quality.

You may be wondering why the jpeg output from LR or PS is not sufficient. Well JPEG compression has advanced over the years and in particular we now have better models of the human visual system. What that means is that newer algorithms can throw away more data from parts of the image that our eyes will never notice. This is called perceptual encoding.

From a practical perspective, jpeg images can now be made smaller, sometimes much smaller, and the differences are not noticeable to us. So an image that was 600K in size might now only be 400k after optimization. This is a 30% reduction in file size and a corresponding reduction in load time.

There are many different programs for recompressing jpeg files and making them smaller. These include JpegMini (paid, has GUI interface), Tiny JPG (free, online), MozJpeg (free), Guetzli (free), and many others. I’ve tried several of these and I prefer to use Guetzli because

  • It’s free and opensource.
  • It’s probably the best performing algorithm in terms of file size.
  • It’s a command line program and easy to script.

You can download Guetzli from here: https://github.com/google/guetzli. I’m on a Mac so I installed it with Homebrew. My process for preparing images is simple.

First, I export images from LR with quality setting 65. I find this is maintains a reason image quality without resulting in too large a file. However, you can use any quality setting but in practice I recommend staying between 60 and 80.

Second, I run guetzli in the terminal (on mac) or from the command line (windows):

    > guetzli -quality 84 input_file.jpg output_file.jpg

This recompresses the jpeg image saving additional space. For Guetzli, I use quality=84 as that results in the greatest reduction in file size without showing visible artifacts. In fact, by design Guetzli won’t run at a lower quality setting.

Guetzli is slow and can take a few minutes to run on larger images. However as a fine art photographer, I’m not producing that many images at once so the time taken is usually acceptable. If I have a large batch of images, I just run it overnight. But if speed becomes a problem you can use an alternative program like MozJpeg.

Another issue with Guetzli is that it strips all metadata and ICC profiles from your image. So if you embed IPTC fields like keywords, captions, copyright status, licensor information, etc these will not be included in the output jpeg file. However, it’s easy enough to add that information back with the program exiftool. Simply run

    > exiftool -TagsFromFile input_file.jpg output_file.jpg

This will copy all the metatags in the original file to the output file. If you want to have more control, you can also pick and choose which tags to copy.

If you need to embed the ICC profile in the output jpg you can do this as follows. First extract the ICC profile from the original image:

    > exiftool -icc_profile -b -w icc input_file.jpg

this produces ICC profile in the file input_file.icc. Now embed that profile in the output file with exiftool

    > exiftool "-icc_profile<=input_file.icc" output_file.tmp

To save myself time and typing, I simply put all my commands into a script which will convert all the jpegs in a given directory.

Example Images

Here are some example images as output by Lightroom and then recompressed with Guetzli. You will probably have to download them and view them at 300-400% in Photoshop before you can see differences.

What about Alternatives like JpegMini or MozJpeg?

Jpeg Mini is a good alternative if you are not comfortable using the command line or with scripting.

Mozjpeg is good if you have many images to convert and you do not have the time to wait for Guetzli to run. It is much faster and will finish in seconds when Guetzli takes minutes. This can be helpful if you have thousands of files to convert.

Can you share your scripts?

Sure, send me an email. But don’t expect any support.