A Comparison of JPEG Compression Levels and Recompression

Over the years, I've standardized on a JPEG compression factor of 15; I find that generally provides the best compromise between image quality and file size for most photographic images.

Although I've done some ad-hoc testing that pointed to compression factor 15 as the sweet spot before, I've never done a formal test. So I performed a JPEG compression series using the Lena reference image*. Note that I resized the image slightly (from 512x512 to 384x384) to keep the file sizes relatively small. The original, uncompressed image size is 433 kilobytes.

compression factor 10 (39 kb) compression factor 15 (30 kb)
Lena image, compression factor 10 Lena image, compression factor 15
compression factor 20 (26 KB) compression factor 30 (16 KB)
Lena image, compression factor 20 Lena image, compression factor 30
compression factor 40 (11 KB) compression factor 50 (9 KB)
Lena image, compression factor 40 Lena image, compression factor 50

Beyond 50 percent compression factor, quality falls off a cliff, so I won't bother displaying anything higher. Here's a more complete breakdown of JPEG compression factor and file size for the 384x384 Lena image:

JPEG Compression Level vs. File Size graph

I was also curious what the image quality and file size penalty was for recompressing a JPEG image. That is, opening a JPEG and re-saving it as a JPEG, including all the artifacts from the original compressed image in the recompression. I've been forced to do this when I couldn't find an uncompressed or high quality version of the image I needed, and I always wondered how much worse it made the image when I recompressed it.

For the recompression test, I started with the uncompressed, resized 384x384 Lena reference image. For each new generation, I opened and saved the previous generation with my standard JPEG compression factor of 15.

Generation 1 (30kb) Generation 2 (30kb)
Lena image, generation 1 Lena image, generation 2
Generation 3 (30kb) Generation 4 (30kb)
Lena image, generation 3 Lena image, generation 4
Generation 5 (30kb) Generation 10 (30kb)
Lena image, generation 5 Lena image, generation 10

I was quite surprised to find that there's very little visual penalty for recompressing a JPEG once, twice, or even three times. By generation five, you can see a few artifacts emerge in the image, and by generation ten, you're definitely in trouble. There's virtually no effect at all on file size, which stays constant at 30-31 kilobytes even through generation 15.

* An entire set of classic reference images is available from the USC-SIPI image database. I distinctly remember that Mandrill image from my Amiga days.

Read more

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood · · Comments

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven't any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don't stop there - read the Story of Your Life novella it was based on

By Jeff Atwood · · Comments

I Fight For The Users

If you haven't been able to keep up with my blistering pace of one blog post per year, I don't blame you. There's a lot going on right now. It's a busy time. But let's pause and take a moment

By Jeff Atwood · · Comments

The 2030 Self-Driving Car Bet

It's my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger

By Jeff Atwood · · Comments