Mozilla today announced a new project called mozjpeg, the goal of which is to provide a production-quality JPEG encoder that improves compression rates. That being said, the company wants to maintain compatibility with “the vast majority” of deployed decoders.

Over the years, the number of images an average website displays has exploded, as has the file size of each image. Since HTML, JS, and CSS files are relatively small in comparison, Mozilla points out photos can “easily make up the bulk of the network traffic for a page load.” The company thus wants to reduce the size of these files, and while JPEG has been in use since around 1992, it is still the most popular lossy compressed image format on the Web.

JPEG is the only lossy compressed image format which has achieved nearly universal compatibility, not just with Web browsers but all software that can display images. As such Mozilla argues that it’s worth trying to optimize it, even with the ongoing search for a successor:

Production JPEG encoders have largely been stagnant in terms of compression efficiency, so replacing JPEG with something better has been a frequent topic of discussion. The major downside to moving away from JPEG is that it would require going through a multi-year period of relatively poor compatibility with the world’s deployed software. We (at Mozilla) don’t doubt that algorithmic improvements will make this worthwhile at some point, possibly soon. Even after a transition begins in earnest though, JPEG will continue to be used widely.

The company talked to engineers and concluded that JPEG encoders haven’t yet reached their full compression potential, even after 20 years and within the constraints of strong compatibility requirements.

Today’s mozjpeg version 1.0 release is a fork of libjpeg-turbo with ‘jpgcrush’ functionality added. The latter is a Perl script written by Loren Merritt which losslessly reduces file sizes by figuring out which progressive coding configuration uses the fewest bits. Results for mozjpeg range from 2-6 percent for PNGs encoded to JPEG by libjpeg-turbo and 10 percent on average for a sample of 1,500 JPEG files from Wikimedia.

Mozilla says it is not aware of any other production encoder that has this functionality built in, so the company decided to include it as mozjpeg’s first feature. The project’s next goal is to improve encoding by making use of trellis quantization. We’ll keep you posted as the project progresses and Mozilla shares its results.

mozjpeg (GitHub)

Top Image Credit: Andreas Krappweis