JpegPresets Module

JPEG quality settings equivalent to the Photoshop settings. Can be used when saving JPEG files.

The following presets are available by default: web_low, web_medium, web_high, web_very_high, web_maximum, low, medium, high, maximum. More presets can be added to the presets dict if needed.

To apply the preset, specify:


To apply only the quantization table:


To apply only the subsampling setting:


Example:"image_name.jpg", quality="web_high")


Subsampling is the practice of encoding images by implementing less resolution for chroma information than for luma information. (ref.:

Possible subsampling values are 0, 1 and 2 that correspond to 4:4:4, 4:2:2 and 4:2:0.

You can get the subsampling of a JPEG with the JpegImagePlugin.get_sampling() function.

In JPEG compressed data a JPEG marker is used instead of an EXIF tag. (ref.:

Quantization tables

They are values use by the DCT (Discrete cosine transform) to remove unnecessary information from the image (the lossy part of the compression). (ref.:,

You can get the quantization tables of a JPEG with:


This will return a dict with a number of arrays. You can pass this dict directly as the qtables argument when saving a JPEG.

The tables format between im.quantization and quantization in presets differ in 3 ways:

  1. The base container of the preset is a list with sublists instead of dict. dict[0] -> list[0], dict[1] -> list[1], …

  2. Each table in a preset is a list instead of an array.

  3. The zigzag order is remove in the preset (needed by libjpeg >= 6a).

You can convert the dict format to the preset format with the JpegImagePlugin.convert_dict_qtables() function.

Libjpeg ref.:

PIL.JpegPresets.presets: dict

A dictionary of all supported presets.