Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jpegoptim vs jpegtran vs mozjpeg

I found two slightly conflicting blog posts on this matter, here I summarize:

  • jpegoptim and jpegtran perform identically and produce identical results, while mozjpeg takes twice as long for very marginal filesize savings
  • mozjpeg takes approx 1.7* the compute time and results in a roughly proportional benefit in filesize savings compared to jpegtran

Adding to confusion, this Reddit thread suggests that mozjpeg uses the same algorithm used in jpegcrush, and that jpegcrush is a wrapper for jpegtran... so we've come full circle? I can only assume that those Reddit comments are wrong, can anyone confirm that?

like image 334
davidtgq Avatar asked Mar 16 '16 20:03

davidtgq


1 Answers

MozJPEG library uses one algorithm inspired by jpegcrush (optimized progressive scans), but technically it's a completely new implementation.

MozJPEG library is a drop-in replacement for the popular libjpeg, so almost every JPEG-related tool can be compiled in "regular" and "MozJPEG" flavors.

There exists a "regular" jpegtran and a MozJPEG version of jpegtran. That's the same program, but the MozJPEG version has different default settings and performs extra work to compress better.

Similarly, jpegoptim is usually built with stock libjpeg, but it's also possible to build it with MozJPEG's version of libjpeg (e.g. ImageOptim does it).


There are two ways to use MozJPEG:

  1. lossless (take an existing JPEG file and make it a bit smaller). That's what MozJPEG's jpegtran does.
  2. lossy (create a new JPEG file from uncompressed pixels, with higher quality/filesize ratio). That's what MozJPEG's cjpeg does, and other tools like jpegoptim can be made to do with MozJPEG.

Both modes of operation are slower than vanilla non-optimizing libjpeg. Lossless optimization does less work, but also achieves smaller gain.

More precise speed analysis is here: https://libjpeg-turbo.org/About/Mozjpeg

Note that "slow" here is relative. In absolute terms it compresses several megapixels per second, so it may be fast enough for most applications.

like image 198
Kornel Avatar answered Oct 20 '22 02:10

Kornel