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:
- lossless (take an existing JPEG file and make it a bit smaller). That's what MozJPEG's
jpegtran
does.
- 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.