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.
Compressing images server-side has several advantages over local tools:
| Property | Value |
|---|---|
| Endpoint | POST /api/compress-image |
| Input | Multipart/form-data with file field image |
| Optional params | quality (1โ100, default 80), format (jpeg, webp) |
| Response | Compressed image bytes (same content-type as input unless format specified) |
| Max file size | 20 MB |
| Auth | Not 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 -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.
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.
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.
Using the built-in requests library (no special SDK needed):
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)
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.
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.
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.
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.
Here's what you can expect from different source types at default quality (80):
| Source Type | Original | Compressed | Savings |
|---|---|---|---|
| JPEG photo (12MP camera) | 4.2 MB | 1.8 MB | 57% |
| PNG screenshot (1920ร1080) | 1.1 MB | 412 KB | 63% |
| WebP illustration | 340 KB | 215 KB | 37% |
| PNG โ WebP (conversion) | 1.1 MB | 286 KB | 74% |
| JPEG banner (1920ร500) | 280 KB | 96 KB | 66% |
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.
The compression API works seamlessly with platforms like n8n, Make, and Zapier via HTTP Request nodes:
https://agentmediatools.com/api/compress-image with the file as multipart form dataBecause the API returns the file directly (no JSON wrapper), you can pipe the response straight into a storage destination without parsing.
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.
Agent Media Tools offers a full suite of image processing APIs:
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