27th June 2014

Losslessly compressing JPEG files is a great but often overlooked way to reduce file sizes on your website or application without losing image quality. Smaller file sizes mean less bandwidth usage for you, and faster page load speeds for your users. What’s not to like about that?

So you want to losslessly compress all your lovely JPEGs but what tool should you use to get the maximum benefit? In this article I compare four tools (jpegoptim, jpegtran, jpegrescan and mozjpeg) and use them to losslessly compress a few different JPEG files to see which gives the best reduction in file size.

Update 1st August 2014

Mozjpeg version 2.1 was released on 29th July and the tests have been updated to include this new version.

Tools Used

Listed below are the tools used in this test. The test script can be found on my github page.

Know of any other tools that provide lossless compression? Let me know and I’ll include them in the test!

jpegoptim v1.4.1 - https://github.com/tjko/jpegoptim

A popular utility for optimizing and compressing JPEG files.

jpegoptim --strip-all --all-progressive --dest=[/path/to/compressed] [/path/to/original]

jpegtran v9a - http://jpegclub.org/jpegtran/

Another popular utility program from the libjpeg-turbo image codec.

jpegtran -copy none -optimize -progressive -outfile [/path/to/compressed] [/path/to/original]

jpegrescan v1.0 - https://github.com/kud/jpegrescan

A perl script for losslessly compressing JPEG files. Originally created by Loren Merritt as jpgcrush.

jpegrescan -s [/path/to/original] [/path/to/compressed]

mozjpeg v1.0 & v2.1 - https://github.com/mozilla/mozjpeg

Recently announced project from Mozilla. Aims to improve lossless JPEG compression even further than the currently available options. It is a fork of libjpeg-turbo with jpgcrush functionality added. For more information see my article on how to compile mozjpeg

mozjpeg -copy none -outfile [/path/to/compressed] [/path/to/original]



  1. mozjpeg
  2. jpegrescan
  3. jpegoptim and jpegtran (joint)

Maybe not unsurprisingly given it’s mission to increase compression, the winner is mozjpeg. Interestingly, v1.0 and v2.1 did better on different photos so there was no clear winner on file size between the two version but v2.1 was between 10% and 20% faster than v1.0 and now also supports baseline JPEGs which may tip the balance.

In a close second was jpegrescan with 2 of the photos reducing by the same amount and the rest only a couple of hundred bytes bigger when compared to mozjpeg but took 2-3 times longer to process the images. These two performed between 1-2% better than both jpegtran and jpegoptim which reduced files by exactly the same amount as each other.

If speed is also an issue then both jpegtran and jpegoptim are valid options performing about 3 times faster than mozjpeg whilst still giving good results, although a good caching solution will negate most of the drawbacks of the longer run times. Also good (as noted above) was mozjpeg 2.1 being between 10% and 20% faster than v1.0 which hopefully bodes well for future releases.

Tests & Results

These are the images used in the tests with the full results and figures:

Comet PANSTARRS with Andromeda Galaxy

Comet PANSTARRS with Andromeda Galaxy

Filesize:6,178,710 bytes (5.9mb)
Dimensions: 4824 x 3161
ToolFilesize ReductionTime Taken
jpegoptim17.635% - 1,089,625 bytes (1mb)2,342ms
jpegtran17.635% - 1,089,625 bytes (1mb)2,221ms
jpegrescan18.875% - 1,166,276 bytes (1.1mb)16,816ms
mozjpeg118.876% - 1,166,323 bytes (1.1mb)6,280ms
mozjpeg218.879% - 1,166,519 bytes (1.1mb)5,272ms
Female mallard

Female Mallard

Filesize:4,213,895 bytes (4mb)
Dimensions: 4928 x 3264
ToolFilesize ReductionTime Taken
jpegoptim6.315% - 266,136 bytes (260kb)1,658ms
jpegtran6.315% - 266,136 bytes (260kb)1,654ms
jpegrescan7.77% - 327,444 bytes (319kb)11,387ms
mozjpeg17.77% - 327,452 bytes (319kb)4,716ms
mozjpeg27.771% - 327,464 bytes (319kb)4,237ms
Jupiter and Moons

Jupiter and Moons

Filesize:3,157,940 bytes (3mb)
Dimensions: 4928 x 3264
ToolFilesize ReductionTime Taken
jpegoptim15.537% - 490,662 bytes (479kb)1,471ms
jpegtran15.537% - 490,662 bytes (479kb)1,469ms
jpegrescan16.574% - 523,402 bytes (523kb)9,672ms
mozjpeg116.574% - 523,402 bytes (523kb)4,046ms
mozjpeg216.514% - 521,533 bytes (521kb)3,484ms


Filesize:2,154,968 bytes (2mb)
Dimensions: 3264 x 2448
ToolFilesize ReductionTime Taken
jpegoptim8.011% - 172,644 bytes (168kb)854ms
jpegtran8.011% - 172,644 bytes (168kb)741ms
jpegrescan8.666% - 186,750 bytes (182kb)5,742ms
mozjpeg18.666% - 186,750 bytes (182kb)2,089ms
mozjpeg28.483% - 182,815 bytes (178kb)1,786ms
House Martins

House Martins

Filesize:1,122,198 bytes (1mb)
Dimensions: 2048 x 1356
ToolFilesize ReductionTime Taken
jpegoptim5.367% - 60,229 bytes (59kb)482ms
jpegtran5.367% - 60,229 bytes (59kb)501ms
jpegrescan6.264% - 70,303 bytes (68kb)3,259ms
mozjpeg16.268% - 70,349 bytes (68kb)1,235ms
mozjpeg26.268% - 70,350 bytes (68kb)1,114ms


Filesize:320,398 bytes (312kb)
Dimensions: 1024 x 768
ToolFilesize ReductionTime Taken
jpegoptim3.642% - 11,672 bytes (168kb)150ms
jpegtran3.642% - 11,672 bytes (168kb)149ms
jpegrescan4.804% - 15,393 bytes (182kb)1,423ms
mozjpeg14.817% - 15,435 bytes (182kb)478ms
mozjpeg24.819% - 15,441 bytes (182kb)335ms

Join in the Discussion