Compress JPG API
POST a JPEG to /v2/convert/jpg/to/compress and get a re-encoded JPEG at quality 75 (or your ImageQuality), with metadata removed. If the new file isn't smaller, you get the original bytes back. The sample at quality 70 went from 25,110 to 15,409 bytes.
- Endpoint
- POST /v2/
convert/ jpg/ to/ compress - Accepts
- jpg
- Sample timing
- 3 ms median of 5 runsHow we measure
- Request size
- Up to 10 MB on the Free plan or 100 MB on paid plans, all files together
Request and response
Every sample below ran against the API before this page was published. Set PDFCONVERSIONAPI_KEY to your key and run it as is.
curl -sS -X POST \
https://api.pdfconversionapi.com/v2/convert/jpg/to/compress \
-H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
-F File=@trailhead-sign.jpg \
--form-string ImageQuality=70 \
-o response.json
# FileData is base64. Save the first file in converted/,
# or print the JSON error.
if jq -e '.Files' response.json > /dev/null; then
mkdir -p converted
name=$(jq -r '.Files[0].FileName' response.json)
jq -r '.Files[0].FileData' response.json \
| base64 --decode > "converted/$name"
else
cat response.json
fiimport base64
import os
import requests
key = os.environ["PDFCONVERSIONAPI_KEY"]
response = requests.post(
"https://api.pdfconversionapi.com/v2/convert/jpg/to/compress",
headers={"Authorization": f"Bearer {key}"},
files=[("File", open("trailhead-sign.jpg", "rb"))],
data={
"ImageQuality": "70",
},
timeout=180,
)
result = response.json()
if not response.ok:
raise SystemExit(f"{result['Code']}: {result['Message']}")
os.makedirs("converted", exist_ok=True)
for file in result["Files"]:
path = os.path.join("converted", file["FileName"])
with open(path, "wb") as out:
out.write(base64.b64decode(file["FileData"]))
print(path, file["FileSize"], "bytes")
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
const form = new FormData();
const file = "trailhead-sign.jpg";
form.append("File", new Blob([await readFile(file)]), file);
form.append("ImageQuality", "70");
const url = "https://api.pdfconversionapi.com/v2/convert/jpg/to/compress";
const key = process.env.PDFCONVERSIONAPI_KEY;
const response = await fetch(url, {
method: "POST",
headers: { Authorization: `Bearer ${key}` },
body: form,
});
const result = await response.json();
if (!response.ok) {
throw new Error(`${result.Code}: ${result.Message}`);
}
await mkdir("converted", { recursive: true });
for (const file of result.Files) {
const path = join("converted", file.FileName);
await writeFile(path, Buffer.from(file.FileData, "base64"));
console.log(path, file.FileSize, "bytes");
}
{
"ConversionCost": 1,
"ConversionTime": 0.003,
"Files": [
{
"FileName": "trailhead-sign.jpg",
"FileExt": "jpg",
"FileSize": 15409,
"FileData": "/9j/4AAQSkZJRgABAgAAAQAB…"
}
]
}Response from our test run on 2026-11-03. ConversionTime shows the median of 5 runs. FileData is shortened here; the real response carries the whole file as base64.
The sample, converted
The same file the code sends. Download the input and the output and compare them yourself.

- Input
- trailhead-sign.jpg (25 KB)
- Output
- trailhead-sign.jpg (15 KB)
- Source
- A drawn mountain trailhead with a wooden sign and a QR code, made by us for these pages and saved at JPEG quality 92 with an EXIF block, an sRGB color profile and 300 dpi. (CC0-1.0). How it was made
- Made by
- 2026-11-04, API build
9eeeb0640aba
Parameters
Send these as form fields next to the file. Names are case-insensitive. If you set one of the documented options below that we don't support yet, the request fails with a 400 that names it instead of returning a file made without it.
| Parameter | What it does |
|---|---|
ImageQualityinteger, default 75 | Quality of the re-encode. On the sample: 40 gave 10,929 bytes, 60 gave 13,159, 70 gave 15,409 and 75 gave 16,411. At 90 the result would have been bigger, so the original came back.Values: 1–100 |
ImageWidthinteger | Shrink while compressing: 200 gave a 200 × 150 file of 6,558 bytes. Any size request turns off the never-bigger check.Values: 1–20000 |
ImageHeightinteger | Target height, or with a width the box the photo must fit.Values: 1–20000 |
ScaleProportionsboolean, default true | false with both sizes stretches to them exactly. |
ScaleIfLargerboolean, default false | true keeps photos narrower than ImageWidth at their own size. |
ScaleImageboolean, default true | false crops the requested size from the top-left corner. |
AlphaColorstring, default white | Only matters when the upload is a PNG with transparency (the route reads files by content): transparent pixels are blended onto this color before the JPEG is written.Values: Color name, #RRGGBB or R,G,B |
FileNamestring | Output name; .jpg is always the extension. |
StoreFileboolean, default false | true returns a 3-hour link instead of the file data. |
Not supported yet
Setting one of these to anything but its default returns 400.
| Option | What to do instead |
|---|---|
CompressionLevel | ConvertAPI's default, Extreme, is accepted; Good or Lossless return 400 "CompressionLevel is not supported yet for jpg/to/compress". Use ImageQuality. |
CompressionPercentage | Any value returns 400; there is no target-percentage mode. |
CompressionFileSize | Any value returns 400; there is no target-size search. |
What carries over, and what doesn't
Kept
- Pixel size, unless you resize
- Color detail: the new JPEG is written without chroma subsampling (4:4:4)
- The original JPEG, byte for byte, whenever re-encoding wouldn't shrink it (EXIF and profile included in that case)
- The upright view of phone photos: a re-encoded file has its pixels turned by the EXIF orientation, so a 300 × 200 test photo tagged Orientation 6 came back 200 × 300
Lost or not yet supported
- Metadata on files that do get smaller: the sample lost its EXIF block, sRGB profile and 300 dpi value.
- A little quality: it is a second lossy encode.
- Progressive and grayscale encodings: output is baseline, three-channel RGB.
Limits
- One JPEG per request.
- Upload size up to 10 MB on the Free plan or 100 MB on paid plans.
- 100,000,000 pixels per image.
- No target file size or percentage; quality is the control.
- 120 seconds per conversion.
Where teams use it
Lighter uploads in a media library
Run each camera or phone JPEG through compression before storing it. Files that were already tight come back unchanged, so a batch never grows.
Shrinking and compressing for e-mail or forms
Send ImageWidth with the quality to get a photo small enough for an attachment limit in one request.
Questions
Can compression make my file bigger?
Not a JPEG, unless you resize. When the re-encoded JPEG is the same size or larger, the API returns your upload unchanged: a JPEG already saved at quality 40 (9,253 bytes) came back byte-identical. With ImageWidth or ImageHeight set, the check is skipped, and that same file at its own width grew to 14,374 bytes. A PNG upload always comes back as a JPEG, even a larger one.
What quality is used by default?
75. For the sample that saved 35% (25,110 to 16,411 bytes). The default output is byte-identical to jpg-to-jpg with ImageQuality=75.
Does ConvertAPI's CompressionLevel work?
Only its default, Extreme. Other levels, CompressionPercentage and CompressionFileSize return 400 so a request never silently does something else. Lower ImageQuality for more compression.
Is EXIF removed?
On every file that gets re-encoded, yes, along with the ICC profile and DPI. A file returned unchanged keeps everything it had.
Can I send a PNG here?
Yes. It is decoded, blended onto AlphaColor (white by default) and written as a JPEG; the sticker sample became a 17,346-byte .jpg. You always get the JPEG, even when it is bigger than the PNG: a 138-byte 64 × 64 PNG of one flat color came back as a 740-byte JPEG. For lossless PNG compression use compress-png.
Convert your first JPG file in a minute.