Browse Docs
On This Page

PNG Compressor

Compress PNG images to reduce file size using lossless and near-lossless compression techniques. Ideal for screenshots, graphics, and images with transparency.

Try PNG compression in the browser →

Compress.FAST uses this same API — what you see in the browser is what you get in code.

Quick reference

Job typeimage.png-compress
Categoryimages
EndpointPOST /compress/png
Input formats.png
Output formatsame as input
Costing1 credit per 5 MB
Max file size1 GB
Optionsresize, compression

Example

cURL
# 1) submit
JOB_ID=$(curl -sS -X POST "https://api.tools.fast/compress" \
  -H "X-Fast-Api-Key: $API_KEY" \
  -F "file=@screenshot.png" | jq -r '.id')

# 2) poll until complete
while true; do
  STATUS=$(curl -sS "https://api.tools.fast/compress/job/${JOB_ID}" \
    -H "X-Fast-Api-Key: $API_KEY" | jq -r '.status')
  [ "${STATUS}" = "Succeeded" ] && break
  [ "${STATUS}" = "Failed" ] || [ "${STATUS}" = "Canceled" ] && exit 1
  sleep 1
done

# 3) download
curl -sS "https://api.tools.fast/compress/job/${JOB_ID}/download" \
  -H "X-Fast-Api-Key: $API_KEY" \
  -o "screenshot-compressed.png"
C#
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("X-Fast-Api-Key", "fast_prod_your_key_here");

using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(File.ReadAllBytes("screenshot.png")), "file", "screenshot.png");

var submit = await http.PostAsync("https://api.tools.fast/compress", form);
var job = await submit.Content.ReadFromJsonAsync<JsonElement>();
var jobId = job.GetProperty("id").GetString();

string status;
do
{
    await Task.Delay(1000);
    var poll = await http.GetFromJsonAsync<JsonElement>(
        $"https://api.tools.fast/compress/job/{jobId}");
    status = poll.GetProperty("status").GetString()!;
} while (status is "Queued" or "Running");

var output = await http.GetByteArrayAsync(
    $"https://api.tools.fast/compress/job/{jobId}/download");
File.WriteAllBytes("screenshot-compressed.png", output);
PowerShell
$headers = @{ "X-Fast-Api-Key" = "fast_prod_your_key_here" }

# 1) submit
$job = Invoke-RestMethod -Method Post "https://api.tools.fast/compress" `
  -Headers $headers `
  -Form @{ file = Get-Item "screenshot.png" }

# 2) poll until complete
do {
  $status = (Invoke-RestMethod "https://api.tools.fast/compress/job/$($job.id)" `
    -Headers $headers).status
  if ($status -in "Failed", "Canceled") { throw "Job $($job.id) $status" }
  Start-Sleep -Seconds 1
} while ($status -ne "Succeeded")

# 3) download
Invoke-RestMethod "https://api.tools.fast/compress/job/$($job.id)/download" `
  -Headers $headers -OutFile "screenshot-compressed.png"

Options

The PNG compressor supports resize and compression mode. See Options for the full reference.

Compression mode

PNG compression is lossy by default. Pass compression.mode: "lossless" for pixel-identical output.

  • Lossy (default) -- quantizes colors then optimizes. Maximum size reduction, near-imperceptible quality loss.
  • Lossless -- Oxipng optimization only. Pixel-identical to the input.

Example with options

cURL
# lossless compression
curl -sS -X POST "https://api.tools.fast/compress" \
  -H "X-Fast-Api-Key: $API_KEY" \
  -F "file=@screenshot.png" \
  -F 'options={"_schemaVersion":1,"compression":{"mode":"lossless"}}'

# lossy compression + resize to 1080p
curl -sS -X POST "https://api.tools.fast/compress" \
  -H "X-Fast-Api-Key: $API_KEY" \
  -F "file=@screenshot.png" \
  -F 'options={"_schemaVersion":1,"resize":{"enabled":true,"preset":"1080p","mode":"pixels","value":null},"compression":{"mode":"lossy"}}'
C#
// lossless compression
var losslessOptions = """{"_schemaVersion":1,"compression":{"mode":"lossless"}}""";

// lossy + resize to 1080p
var combinedOptions = """{"_schemaVersion":1,"resize":{"enabled":true,"preset":"1080p","mode":"pixels","value":null},"compression":{"mode":"lossy"}}""";

using var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(File.ReadAllBytes("screenshot.png")), "file", "screenshot.png");
form.Add(new StringContent(combinedOptions), "options");

var response = await http.PostAsync("https://api.tools.fast/compress", form);
PowerShell
# lossless compression
Invoke-RestMethod -Method Post "https://api.tools.fast/compress" `
  -Headers @{ "X-Fast-Api-Key" = $Key } `
  -Form @{
    file    = Get-Item "screenshot.png"
    options = '{"_schemaVersion":1,"compression":{"mode":"lossless"}}'
  }

Notes

  • Output format: .png -- same as input.
  • Transparency (alpha channel) is preserved during compression.
  • For compressing PNG files alongside other image formats, use the Universal compressor instead.
Copied.