← Back to blog

Free Image Compression API for JPEG, PNG & WebP

Published July 10, 2026 Β· Updated August 6, 2026 Β· Eric Β· 5 min read

Compress an image now

Use the free browser image compressor, or send an image to POST /api/compress-image from curl, Python, or an AI agent.

Images are often among the heaviest resources on a webpage. Every kilobyte you shave off can mean faster load times, lower bandwidth use, and a better mobile experience. Running image optimization locally can also mean installing native encoders, wrestling with build tools, and adding another CI step.

What if you could just POST an image and get back a compressed version β€” no local tooling required?

Agent Media Tools offers a free image compression API at POST /api/compress-image that takes JPEG, PNG, or WebP input and returns JSON with the size savings and a temporary download URL. No signup is required for basic use.

Why Use an Image Compression API?

Compressing images server-side has several advantages over local tools:

API Overview

PropertyValue
EndpointPOST /api/compress-image
InputMultipart/form-data with file field image
Optional paramsquality (1–100; default 70)
ResponseJSON with originalSize, compressedSize, savingsPercent, and downloadUrl
Max file size20 MB
AuthNot required for basic use

You send an image file, optionally choose a quality level, and receive a temporary URL for the processed result. The endpoint preserves the source format. To change formats, use the separate image converter.

curl Examples

πŸ’‘ Windows users: Run these from Git Bash or WSL β€” PowerShell's curl is an alias for Invoke-WebRequest. Or use Invoke-RestMethod with the same URL/body.

Basic JPEG Compression

curl -X POST https://agentmediatools.com/api/compress-image \
  -F "image=@photo.jpg" \
  -F "quality=70"

The JSON response includes the measured savings and a downloadUrl. Open that URLβ€”or fetch it in a second requestβ€”to save the compressed image.

Aggressive Compression (Smaller Files)

curl -X POST https://agentmediatools.com/api/compress-image \
  -F "image=@photo.jpg" \
  -F "quality=30"

Quality 30 is aggressive and may introduce visible artifacts. Compare the returned size metadata and inspect the result before using it for a production asset.

Need WebP instead?

Compression preserves the input format. Use the free image converter when you want PNG or JPEG input converted to WebP or AVIF.

Python Examples

Using the built-in requests library (no special SDK needed):

Simple Compression

import requests

url = "https://agentmediatools.com/api/compress-image"
files = {"image": open("screenshot.png", "rb")}
data = {"quality": 75}

resp = requests.post(url, files=files, data=data)
resp.raise_for_status()
result = resp.json()

download = requests.get(
    "https://agentmediatools.com" + result["downloadUrl"]
)
download.raise_for_status()
with open("screenshot-compressed.png", "wb") as f:
    f.write(download.content)

print(f"Saved {result['savingsPercent']}%")

Batch Compression (Entire Directory)

import requests
import os
from pathlib import Path

url = "https://agentmediatools.com/api/compress-image"
input_dir = Path("./images")
output_dir = Path("./images-compressed")
output_dir.mkdir(exist_ok=True)

for img_path in input_dir.glob("*.png"):
    with open(img_path, "rb") as f:
        resp = requests.post(
            url,
            files={"image": f},
            data={"quality": 70}
        )
    resp.raise_for_status()
    result = resp.json()
    download = requests.get(
        "https://agentmediatools.com" + result["downloadUrl"]
    )
    download.raise_for_status()

    out_path = output_dir / img_path.name
    with open(out_path, "wb") as f:
        f.write(download.content)

    print(f"{img_path.name}: {result['savingsPercent']}% saved")

This script walks every PNG in ./images, compresses it at quality 70, then downloads the result while preserving the PNG format.

Using the Python SDK

There's no separate SDK package to install β€” just use Python's built-in requests library as shown above. The compression endpoint is a standard REST API, so any HTTP client works. For MCP-based IDEs like Claude Desktop, install the MCP extension instead.

Compression Via CLI (amt)

The official amt CLI has a built-in compress command:

# Install
npm install -g agentmediatools-cli

# Compress an image
amt image compress photo.jpg --quality 70

# Output: Success: Compressed β†’ <temporary-name>.jpg (... KB, saved ...%)

The CLI handles file upload, safe output creation, and auto-naming. Add --json for shell scripts and agents; failures return a nonzero exit code.

Compression Via MCP (for AI Agents)

If you use Claude Desktop, Cursor, or any MCP-compatible IDE, you can install the Agent Media Tools MCP server and compress images directly from your chat:

# In Claude, just say:
"Compress this image: https://example.com/photo.jpg"

# Or specify quality:
"Compress this image at quality 50:
 https://example.com/banner.png"

The MCP server exposes compress_image as a tool. Claude handles the file download, uploads it to the API, and returns the compressed result β€” all without you writing a single line of code.

What Determines the File-Size Savings?

Results depend on the source format, image complexity, previous optimization, dimensions, and chosen quality. A camera JPEG and a flat-color PNG can behave very differently. The API reports originalSize, compressedSize, and savingsPercent for every request, so your workflow can use measured results instead of assuming a fixed percentage.

Integrating With Automation Tools

The compression API works seamlessly with platforms like n8n, Make, and Zapier via HTTP Request nodes:

n8n Workflow (3 nodes)

  1. Trigger (Webhook or Cron) β€” receive or find an image URL
  2. HTTP Request β€” POST to https://agentmediatools.com/api/compress-image with the file as multipart form data
  3. Download β€” fetch the returned downloadUrl, then save or deliver the result

The first request returns metadata and a temporary download URL. Automation tools can feed that URL into a second HTTP node before uploading the file to storage.

Pricing and Limits

The image compression API can be tried without an account within the shared anonymous limit of 10 tool calls per day. A free login raises the shared limit to 25 calls per day, while Pro provides 1,000 calls per day. See the current pricing page for route-specific upload and credit limits.

Rate limits reset at midnight UTC. The response header X-RateLimit-Remaining tells you how many requests you have left.

What About Other Image APIs?

Agent Media Tools offers a full suite of image processing APIs:

Try It Now β€” No Signup Needed

Grab any JPEG or PNG image and run the curl command above. The response reports the measured savings and gives you a temporary download URL. No account, API key, or credit card is required for basic use.

β†’ Visit Agent Media Tools  Β·  πŸ“– API Docs  Β·  πŸ’¬ Discord

Tags: image compression, WebP, JPEG optimization, free API, image processing

Related: Compress images free β†’ Β· Agent skill β†’ Β· Resize β†’ Β· All image tools β†’