Skip to content
pdfconversionapi

Compress PNG API

POST a PNG to /v2/convert/png/to/compress and get the same image in fewer bytes: the pixel data is recompressed losslessly and text chunks are removed. At CompressionLevel=Extreme the sample went from 40,051 to 33,394 bytes with every pixel unchanged.

Endpoint
POST /v2/convert/png/to/compress
Accepts
png
Sample timing
0.478 s 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/png/to/compress \
  -H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
  -F File=@garden-plot-badge.png \
  --form-string CompressionLevel=Extreme \
  -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
fi
200 OK0.478 s median1 file, 33 KB
{
  "ConversionCost": 1,
  "ConversionTime": 0.478,
  "Files": [
    {
      "FileName": "garden-plot-badge.png",
      "FileExt": "png",
      "FileSize": 33394,
      "FileData": "iVBORw0KGgoAAAANSUhEUgAA…"
    }
  ]
}

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.

First page of garden-plot-badge.png, rendered by the API
Input
garden-plot-badge.png (39 KB)
Output
garden-plot-badge.png (33 KB)
Source
A round garden-plot sticker with a QR code, a transparent background and a soft drop shadow, drawn by us for these pages. (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.

ParameterWhat it does
CompressionLevelenum, default 2How hard the optimizer searches. Lossless is level 2, Good 4 and Extreme 6; every level is lossless. The sample: level 0 36,970 bytes, 2 33,646, 4 and 6 33,394. Note that ConvertAPI documents Extreme as its default; ours is level 2 when you send nothing.Values: Lossless, Good, Extreme, or 0–6
ImageWidthintegerResize before optimizing: 150 gave a 150 × 150 file of 19,152 bytes. A resized PNG loses its pHYs chunk unless ImageResolution is set too.Values: 1–20000
ImageHeightintegerTarget height, or with a width the box to fit.Values: 1–20000
ScaleProportionsboolean, default truefalse stretches to the exact box when both sizes are set.
ScaleIfLargerboolean, default falsetrue keeps small images at their size when a larger width is asked for.
ScaleImageboolean, default truefalse crops at the requested size instead of scaling.
ImageResolutionintegerOnly read together with a resize, where it writes the DPI of the new image (ImageWidth=150 with 300 gave a 300 dpi pHYs).Values: 10–800
FileNamestringOutput name, .png kept.
StoreFileboolean, default falsetrue returns a 3-hour download link.

Not supported yet

Setting one of these to anything but its default returns 400.

OptionWhat to do instead
CompressionPercentageReturns 400 "CompressionPercentage is not supported yet for png/to/compress". Compression here is lossless, so there is no size target to aim for.
CompressionFileSizeReturns 400; no target-size mode.

What carries over, and what doesn't

Kept

  • Every pixel and alpha value: the decoded output matched the sample exactly
  • Palette PNGs as palettes, with their transparent index (a 1,126-byte 64 × 64 test file became 132 bytes)
  • 16-bit depth (a 32 × 32 16-bit gray test file went from 110 to 96 bytes)
  • Animation: a 3-frame animated PNG kept all three frames, also when tagged with an EXIF orientation
  • The pHYs DPI and the color profile, whether an ICC profile or sRGB and cICP chunks, with or without an orientation tag
  • The upright view of a PNG with an EXIF orientation tag. Its pixels stay as stored and a 26-byte EXIF chunk holding only the orientation goes back in: a 300 × 200 test PNG tagged Orientation 6 came back 300 × 200, still tagged 6, and our png-to-jpg drew it 200 × 300. With ImageWidth=300 the pixels are turned instead: 300 × 450

Lost or not yet supported

  • Text chunks: the sample's Description chunk is gone.
  • The pHYs chunk and the color profile when you also resize. ImageResolution writes a DPI back; no option keeps the profile.
  • Big savings on PNGs that were written well to begin with: the sample saved 16.6%, and a PNG that is already optimal comes back unchanged.
  • EXIF tags other than the orientation. A test PNG tagged with a software name, a date and a maker kept only its Orientation 6, and one tagged Orientation 1 lost its EXIF chunk.

Limits

  • One PNG per request.
  • Upload size up to 10 MB on the Free plan or 100 MB on paid plans.
  • 100,000,000 pixels per image, checked before the optimizer runs.
  • A file that isn't a PNG, such as a JPEG renamed .png, returns 422 "the input file could not be read: it is not a PNG image". Sending ImageWidth or ImageHeight doesn't change that: our sign photo was refused the same way.
  • 120 seconds per conversion.

Where teams use it

Smaller assets in a build or upload step

Run icons, screenshots and illustrations through compression before they ship. Pixels don't change, so nothing needs a visual review afterwards.

Stripping text chunks from exported PNGs

Design and screenshot tools write descriptions, software names and other text into PNGs. The optimizer removes text chunks and EXIF tags and keeps the color profile and the DPI. A PNG that must be shown turned keeps a small EXIF chunk holding only its orientation.

Questions

Is any quality lost?

No. Every level is lossless; the decoded output of the sample matched the input on every channel of every pixel.

Which level should I use?

Extreme (6) for the smallest file. On the sample it beat the default level 2 by 252 bytes, and matched level 4. Level 0 still saved 3,081 bytes.

What if the PNG can't be made smaller?

You get the original bytes back. The sample's default-level output (33,646 bytes) sent through again came back byte for byte, and so did the 33,394-byte Extreme sample at Extreme.

Can I get a much smaller file by allowing some loss?

Not on this route. For photos saved as PNG, png-to-jpg or png-to-webp change the format; for flat art, png-to-gif with its 256-color palette halved the sample.

Convert your first PNG file in a minute.