Concepts
The quality scale
What a quality setting means for each kind of file, and how to choose one.
Image quality, 0 to 100
image.quality is a whole number from 0 to 100. The default is 75. A higher number keeps more detail and gives a larger file. The same number is used for every image format, but each encoder reads it in its own way.
| Output format | 0 to 95 | 96 to 100 |
|---|---|---|
| JPEG | Lossy. The number is passed to the encoder (mozjpeg) unchanged. | The same. JPEG is always lossy. |
| AVIF | Lossy. The number is passed to the encoder unchanged, for colour and for transparency. | The same. AVIF output is always lossy. |
| WebP | Lossy at that quality. | Lossless. Every pixel is kept exactly. |
| PNG | The colours are reduced to a palette, then the file is optimised without further loss. | Lossless. The file is only optimised. |
| HEIC | Lossy. The number is passed to the encoder unchanged. | The same. |
| GIF | Not used. GIF output has no quality setting. | Not used. |
Because WebP and PNG switch to lossless at 96, a file at 96 can be several times larger than the same file at 95. Use 96 or above only when you need exact pixels.
The number applies to compress requests. If the result at your setting is larger than the input, the API tries once more at a lower setting before it gives up. See Kept original.
How PNG uses the number
Below 96, a PNG is compressed in two steps. First the colours are reduced to a palette. The quality number sets the range the palette step must stay inside. Then the file is optimised losslessly, at an effort level that also follows the number.
palette minimum = max(0, round(0.8 × quality − 10))
palette maximum = min(100, quality + 10)
optimisation level = round(quality ÷ 100 × 4) + 2| Quality | Palette range | Optimisation level |
|---|---|---|
| 0 | 0 to 10 | 2 |
| 30 | 14 to 40 | 3 |
| 50 | 30 to 60 | 4 |
| 75 (default) | 50 to 85 | 5 |
| 95 | 66 to 100 | 6 |
| 96 to 100 | No palette step (lossless) | 6 |
If the palette step cannot reach the minimum, or would make the file larger, it is skipped and the file is only optimised.
PDF presets
pdf.quality is one of five presets. The default is medium. A preset sets how the images inside the PDF are resampled and recompressed. Text and vector drawings are not changed.
| Preset | Longest side of each image | JPEG quality of each image |
|---|---|---|
tiny | 600 px | 25 |
small | 900 px | 45 |
medium | 1200 px | 60 |
large | 1800 px | 75 |
original | 2400 px | 88 |
Images smaller than 10,000 pixels and JPEGs smaller than 8,192 bytes are left alone. An image is replaced only when the new version is smaller. The file structure is then rewritten and its streams are compressed.
Video tiers
video.quality is a named tier. The default is high. Each tier maps to a constant rate factor (CRF) for the chosen codec. A lower CRF keeps more detail and gives a larger file.
| Codec | tiny | low | balanced | high | maximum | web |
|---|---|---|---|---|---|---|
| H.265 (default) | 34 | 30 | 26 | 24 | 18 | 28 |
| H.264 | 31 | 26 | 22 | 19 | 14 | 24 |
| VP9 | 41 | 36 | 31 | 26 | 16 | 26 |
video.crf(0 to 63) replaces the tier's CRF with your own value.- The encoder preset is
medium.video.slowchanges it toslow, which takes longer and gives a smaller file at the same CRF.video.presetsets it directly. - The audio track is encoded at the
video.audio_qualitytier, using the bitrates in the next section. The default ishigh. - WebM output always uses VP9, whatever
video.codecsays.
Audio tiers
audio.quality is a named tier. The default is high. Each tier is a bitrate.
| Tier | Bitrate |
|---|---|
tiny | 64 kbit/s |
low | 96 kbit/s |
balanced | 128 kbit/s |
high | 192 kbit/s |
maximum | 320 kbit/s |
audio.bitrate_kbps (16 to 512) replaces the tier's bitrate with your own value. The lossless formats (wav, flac and alac) take no bitrate, so the tier has no effect on them.
Quality when converting
The convert endpoint changes the format and keeps as much quality as it can. It does not read the quality options above. It uses fixed settings:
| Conversion | Setting |
|---|---|
| Image to JPEG, WebP, AVIF, HEIC or TIFF | Quality 95 |
| PDF page to JPEG | Quality 95 |
| Video to MP4, MOV or MKV | H.264 at CRF 18, AAC audio at 192 kbit/s |
| Video to WebM | VP9 at CRF 18, Opus audio at 160 kbit/s |
| Audio to M4A | AAC at 192 kbit/s |
| Audio to MP3 | Variable bitrate, LAME quality 2 |
| Audio to OGG | Opus at 160 kbit/s |
| Audio to WAV or FLAC | Lossless |
To change the format and choose the quality in one request, use compress with a format option, for example image.format=avif&image.quality=60.
Choosing a setting
- Images. Start with the default, 75. Go lower, to between 50 and 65, for thumbnails and background pictures. Go higher, to between 85 and 90, when fine detail matters, as in product photos. Check the result by eye at the size it will be shown.
- PDFs.
mediumsuits reading on a screen.tinyandsmallsuit email attachments where the pictures only need to be recognisable.largeandoriginalsuit documents that will be printed. - Video.
highis close to the source. For H.265 and H.264,websits betweenlowandbalancedand suits video played in a web page. - Audio. Speech stays clear at
tinyorlow, more so withaudio.channels=mono. Usebalancedorhighfor music.
Every option and its allowed values are listed in Options.