Guide
Compress files
Reduce file size by quality or target size.
The compress operation reduces file size for images, PDFs, audio and video while keeping the original format. You control the trade-off between size and fidelity with a handful of options — pick a compression level, cap the output at a specific size, or strip metadata to shave off extra bytes.
Basic request
Submit a compress job by sending the source file URL and a conversion entry with the compress target. The example below applies a high compression level.
{
"input": [
{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example.jpg"
}
],
"conversion": [
{
"category": "operation",
"target": "compress",
"options": {
"compression_level": "high"
}
}
]
}
curl -X POST https://api.api2convert.com/v2/jobs \
-H "x-oc-api-key: <your-api-key>" \
-H "Content-Type: application/json" \
-d @job.json
Options
| Option | Type | Description |
|---|---|---|
compression_level |
string | Preset strength: low, medium, high or best. |
quality |
integer | Output quality from 0 (smallest) to 100 (best). Applies to lossy formats. |
compression_target |
string | Output format to compress into, when different from the source. |
file_size |
integer | Target maximum output size in KB. |
file_size_perc |
integer | Target output size as a percentage of the original file. |
strip_metadata |
boolean | Remove embedded metadata (EXIF, tags) to reduce size further. |
Compress by quality
Set an explicit quality value to control how aggressively a lossy format such as JPG is re-encoded. Lower values mean smaller files and more visible artifacts.
{
"input": [
{
"type": "remote",
"source": "https://example-files.online-convert.com/raster%20image/jpg/example.jpg"
}
],
"conversion": [
{
"category": "operation",
"target": "compress",
"options": {
"quality": 70,
"strip_metadata": true
}
}
]
}
Target a file size
Use file_size to cap the output at a fixed number of kilobytes. This is handy when an upload or email attachment must stay under a known limit — for example, keeping a PDF under 2 MB.
{
"input": [
{
"type": "remote",
"source": "https://example-files.online-convert.com/document/pdf/example.pdf"
}
],
"conversion": [
{
"category": "operation",
"target": "compress",
"options": {
"file_size": 2048
}
}
]
}
Use either file_size or file_size_perc, not both, in the same request. The engine compresses until the target is met or the lowest acceptable quality is reached, so very small targets may not be achievable for every input.
Related guides
Compression keeps the source format. To change the format as well, see the format-specific guides and check which targets accept compress in the formats explorer.
Live options
Loading options…