Add optimize=True to every Pillow JPEG save. On a 4964 × 2782 photo at quality 75 it cut the file from 772,155 bytes to 704,228 bytes (8.8% smaller) and the decoded pixels stayed identical. progressive=True saved about the same or a little more, but took 4 times as much CPU as the plain save. Below are all four combinations at two sizes and two qualities.
What do optimize and progressive actually change?
Neither flag touches the pixels. Both change how the encoder writes the same quantised data. The Pillow JPEG docs say optimize makes the encoder "make an extra pass over the image in order to select optimal encoder settings", and progressive stores the file as a progressive JPEG. In practice, optimize builds Huffman tables fitted to this image instead of the generic default tables. progressive splits the data into scans that refine the picture as it loads.
So the question is not "does quality drop". It is "what do I pay in CPU for the bytes I save". I measured that.
The script
It saves one image four ways (optimize on or off, progressive on or off), decodes each result and compares the pixels with the plain save, and times the encode.
Run it as python jpeg_flags.py camera.jpeg. The timer is time.process_time(), which counts the CPU time of this process, so other jobs on the machine do not distort it. Each time is the median of 5 encodes, and the image is already decoded in memory, so only the encode is timed.
What did it print?
How much do the bytes change?
Here are the savings against the plain save (all pixels identical):
- Camera photo, quality 75: optimize saved 8.8% (704,228 B), progressive saved 8.1% (709,747 B).
- Camera photo, quality 85: optimize saved 3.5% (1,069,842 B), progressive saved 4.9% (1,054,225 B).
- Web photo, quality 75: optimize saved 3.8% (158,659 B), progressive saved 3.9% (158,522 B).
- Web photo, quality 85: optimize saved 1.7% (225,068 B), progressive saved 2.5% (223,183 B).
Two things stand out. The saving shrinks as quality rises: at quality 85 the extra Huffman work has fewer small values to squeeze. And neither flag wins everywhere. At quality 75 on the camera photo, optimize beat progressive (704,228 B against 709,747 B). At quality 85 on the same photo, progressive won (1,054,225 B against 1,069,842 B).
Note: the two progressive rows are byte-for-byte the same size whether
optimizeis on or off (709,747 B in both camera q75 rows). In my runsprogressive=Truegave the optimized result by itself, sooptimize=True, progressive=Truecosts nothing extra overprogressive=True. I did not read the encoder source to confirm why. I only saw the equal bytes in all four pairs.
What does it cost in CPU time?
- Camera photo, quality 75: plain 27.8 ms, optimize 56.3 ms (2.0×), progressive 115.3 ms (4.1×).
- Web photo, quality 75: plain 4.5 ms, optimize 10.1 ms (2.2×), progressive 20.9 ms (4.6×).
Optimize roughly doubles the encode. Progressive roughly quadruples it. For one upload that is nothing. For a batch of 10,000 full-size photos, the 59 ms gap between progressive and optimize adds about 10 minutes of CPU.
Which flags should you use?
-
Always set
optimize=True. It is lossless, it never made a file bigger in these runs, and it costs a few milliseconds per web-sized image. -
Add
progressive=Truefor photos that travel over the web. Progressive JPEGs paint a blurry full image first and sharpen as bytes arrive. Againstoptimizealone it was smaller in 3 of the 4 cases here and larger in 1. The extra CPU is a one-time cost per file. - Measure before you use progressive on tiny thumbnails. I did not test any size below 1920 px wide.
im.save("out.jpg", "JPEG", quality=80, optimize=True, progressive=True)
To check the result on your own files without writing code, run them through the JPG compressor and compare the bytes. The image optimization guide covers where this step fits in a full pipeline.
How I measured
- Machine: Apple M1 Pro, macOS, 2026-10-18.
- Python 3.9.6 in a fresh venv, Pillow 11.3.0 with libjpeg-turbo 3.1.1 (from
PIL.features). - Input:
image-compressor-sample-camera-photo.jpegfrom the site (4964 × 2782). The "web" photo is the same file resized to 1920 × 1076 with LANCZOS. - Times: CPU time (
time.process_time()), median of 5, encode only. The machine was busy with other jobs while I ran this, which is why I used CPU time and not the wall clock. - Pixel check: each output decoded back to RGB and compared with
numpy.array_equalagainst the plain save. All 16 matched.
What I did not test
Other quality values, CMYK or grayscale sources, mozjpeg (Pillow uses libjpeg-turbo here), and how fast a progressive file paints in a browser.
I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

Top comments (0)