โ† Back to blog

Free Image Compression API: Shrink JPEGs & WebP by 80% with curl or Python

July 10, 2026 ยท Eric ยท 5 min read

Images make up 60โ€“70% of the average webpage weight. Every kilobyte you shave off means faster load times, lower bandwidth bills, and happier users โ€” especially on mobile. But running image optimization locally means installing libraries (libjpeg, mozjpeg, cwebp), wrestling with build tools, and adding yet 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 a compressed file. No signup required for basic use. Here's how it works in curl, Python, and through the MCP server for AI agents.

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 80), format (jpeg, webp)
ResponseCompressed image bytes (same content-type as input unless format specified)
Max file size20 MB
AuthNot required for basic use

You send an image file, optionally choose a quality level and target format, and get back a smaller file. The server handles mozjpeg for JPEGs and cwebp for WebP โ€” the same encoders used by CloudFlare and Google's PageSpeed Insights.

curl Examples

Basic JPEG Compression

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

This sends photo.jpg and saves the compressed result as compressed.jpg. Default quality is 80, which typically saves 40โ€“60% with no visible difference.

Aggressive Compression (Smaller Files)

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

Quality 30 is aggressive โ€” expect 70โ€“85% savings with some visible artifacts. Good for thumbnails or previews.

Convert to WebP

curl -X POST https://agentmediatools.com/api/compress-image \
  -F "image=@photo.png" \
  -F "format=webp" \
  -F "quality=80" \
  -o photo.webp

PNG input โ†’ WebP output. WebP regularly beats JPEG by 25โ€“35% at the same quality level. If you're targeting modern browsers (which all support WebP since 2020), this is your best bet.

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")}
params = {"quality": 75}

resp = requests.post(url, files=files, params=params)

with open("screenshot-compressed.png", "wb") as f:
    f.write(resp.content)

print(f"Compressed: {len(resp.content):,} bytes")
# Output: Compressed: 142,380 bytes (was 412,000)

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},
            params={"quality": 70, "format": "webp"}
        )
    
    out_path = output_dir / f"{img_path.stem}.webp"
    with open(out_path, "wb") as f:
        f.write(resp.content)
    
    original_kb = img_path.stat().st_size / 1024
    compressed_kb = len(resp.content) / 1024
    savings = (1 - len(resp.content) / img_path.stat().st_size) * 100
    print(f"{img_path.name}: {original_kb:.0f} KB โ†’ {compressed_kb:.0f} KB ({savings:.0f}% saved)")

This script walks every PNG in ./images, compresses and converts to WebP at quality 70, and saves the results โ€” all in parallel-friendly single requests.

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 amt CLI tool has a built-in compress command:

# Install
npm install -g amt

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

# Output: Compressed โ†’ compressed_photo.jpg (142.3 KB, saved 58%)

The CLI handles file upload, progress, and auto-naming โ€” useful in shell scripts and cron jobs.

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 at quality 50 and convert to WebP:
 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.

Real-World Compression Benchmarks

Here's what you can expect from different source types at default quality (80):

Source TypeOriginalCompressedSavings
JPEG photo (12MP camera)4.2 MB1.8 MB57%
PNG screenshot (1920ร—1080)1.1 MB412 KB63%
WebP illustration340 KB215 KB37%
PNG โ†’ WebP (conversion)1.1 MB286 KB74%
JPEG banner (1920ร—500)280 KB96 KB66%

Pro tip: Converting PNG screenshots to WebP at quality 80 is almost always the highest-savings move. PNG is lossless by design, so there's enormous room for lossy compression with negligible visual difference.

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. S3 / Dropbox / HTTP Response โ€” save or deliver the compressed result

Because the API returns the file directly (no JSON wrapper), you can pipe the response straight into a storage destination without parsing.

Pricing and Limits

The image compression API is free for up to 100 requests per day with no API key. For higher volume or priority processing, check the pricing page โ€” the $15/mo Developer plan bumps you to 5,000 requests/day.

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. You'll get back a compressed version in under a second. No account, no API key, no credit card.

โ†’ Visit Agent Media Tools  ยท  ๐Ÿ“– API Docs  ยท  ๐Ÿ’ฌ Discord

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