# Image Compressor (`onescales/image-compressor`) Actor

Compress images in bulk without losing quality you can see. Paste a list of image URLs, choose lossy or lossless, and get every file compressed as small as it will go — with a download link for each one and a single ZIP of the whole batch at the end.

- **URL**: https://apify.com/onescales/image-compressor.md
- **Developed by:** [One Scales](https://apify.com/onescales) (community)
- **Categories:** Developer tools, Other, SEO tools
- **Stats:** 2 total users, 2 monthly users, 100.0% runs succeeded, 3 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Image Compressor

***

### Introduction

**Compress images in bulk without losing quality you can see.** Paste a list of image URLs, choose lossy or lossless, and get every file compressed as small as it will go — with a download link for each one and a single ZIP of the whole batch at the end.

Every image is run through several different encoders, the results are compared, and whichever came out smallest wins. Built on **MozJPEG** and **libimagequant** — two best-in-class open source image encoders — plus SVGO for vector files.

Two rules are never broken. **The output is never larger than the input** — if no encoder beats the original, you get the original back untouched. And **lossless means lossless** — every lossless result is decoded and compared pixel-for-pixel against the source before it is saved.

***

### Features

- **Smallest-wins compression** — several encoders per image, best result kept, never larger than the original.
- **Verified lossless mode** — pixel-for-pixel checked before saving, so archives and masters are provably unchanged.
- **All common formats** — JPEG, PNG, WebP, GIF, TIFF, AVIF, HEIC and SVG, detected from the file itself rather than the URL.
- **One-click bulk download** — every successful image bundled into a single `all-images.zip` as the final result row.
- **Built for scale** — flat memory use at any batch size, residential proxy support, and 3 automatic retries per file.

***

### Use Cases

- **Speed up a website** — images are usually the heaviest thing on a page; halving them halves load time.
- **Cut CDN and bandwidth bills** — egress costs scale directly with bytes served.
- **Improve SEO** — page speed is a ranking factor and image weight is the biggest lever most sites have.
- **Optimize a product catalog** — store photography is often uploaded straight from a camera, uncompressed and full of EXIF.
- **Clean up after a migration** — process an entire media library in one pass instead of one file at a time.
- **Archive without loss** — lossless mode reduces size with a guarantee that not one pixel changed.
- **Fit email and app assets under size limits** — without opening an image editor.
- **Strip metadata before publishing** — EXIF, GPS and camera details removed as part of compression.

***

### Input

Configure the actor in the UI, or pass the same fields via the API.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| **Image URLs** (`imageUrls`) | Array of strings | Yes | Direct image URLs, one per line. Redirects are followed and the file type is detected from the image data, so extensions are optional. |
| **Compression Type** (`compressionType`) | `lossy` | `lossless` | No — defaults to `lossy` | `lossy` targets quality 85 for the smallest files. `lossless` guarantees a pixel-identical result. |
| **Proxy Configuration** (`proxyConfiguration`) | Object | No — defaults to residential | Proxy used for downloading the images. Compression itself runs locally and is unaffected. |

```json
{
  "imageUrls": [
    "https://example.com/photos/beach.jpg",
    "https://cdn.example.com/logo.png",
    "https://example.com/assets/icon.svg"
  ],
  "compressionType": "lossy",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": ["RESIDENTIAL"]
  }
}
```

***

### Output

One row per image, in the order you submitted them, each with a direct download link. **The final row is the ZIP** containing every image that compressed successfully — the quickest way to grab the whole batch. Export the table as CSV, JSON, or Excel.

| Field | Type | Description |
|-------|------|-------------|
| `imageUrl` | string | The image URL that was requested |
| `fileName` | string | Suggested file name for the compressed image |
| `format` | string | Format detected from the file bytes, or `zip` on the final row |
| `mode` | string | `lossy` or `lossless` |
| `width` | integer | Image width in pixels |
| `height` | integer | Image height in pixels |
| `originalBytes` | integer | Size of the original image |
| `compressedBytes` | integer | Size after compression, never larger than the original |
| `savedBytes` | integer | Bytes saved |
| `savedPercent` | number | Percentage of the original size saved |
| `encoder` | string | Which encoder won, or `none (already optimal)` |
| `pixelIdentical` | boolean | True when verified pixel-for-pixel identical to the source |
| `downloadUrl` | string | Direct download link to the compressed file |
| `status` | string | `success`, or `error: <reason>` |

```json
[
  {
    "imageUrl": "https://example.com/photos/beach.jpg",
    "fileName": "beach.jpg",
    "format": "jpeg",
    "mode": "lossy",
    "width": 1280,
    "height": 575,
    "originalBytes": 221419,
    "compressedBytes": 173739,
    "savedBytes": 47680,
    "savedPercent": 21.5,
    "encoder": "mozjpeg-q85",
    "pixelIdentical": false,
    "downloadUrl": "https://api.apify.com/v2/key-value-stores/.../records/00000-beach.jpg",
    "status": "success"
  },
  {
    "imageUrl": "ALL IMAGES (ZIP)",
    "fileName": "all-images.zip",
    "format": "zip",
    "mode": "lossy",
    "width": 0,
    "height": 0,
    "originalBytes": 445985,
    "compressedBytes": 228064,
    "savedBytes": 217921,
    "savedPercent": 48.9,
    "encoder": "zip bundle of 2 images",
    "pixelIdentical": false,
    "downloadUrl": "https://api.apify.com/v2/key-value-stores/.../records/all-images.zip",
    "status": "success"
  }
]
```

**Good to know**

- **Formats are preserved** — this optimizes images, it does not convert them.
- **Lossless savings are modest.** On an already-optimized file the honest answer is 0%, and the original is returned unchanged. Animated GIFs usually come back unchanged in lossless mode, because re-encoding shifts the palette. Use lossy for real reductions.
- **Quality is fixed at 85** in lossy mode — the point where savings are large and loss is invisible.
- **Files over 50 MB** are skipped with an error status.
- **Retries** — every download and file write is retried up to 3 times (2s, 8s, 20s), rotating proxy IP each attempt. Permanent failures like a 404 fail fast.
- **Speed and memory** — roughly 600 images per minute on a 2 GB run. Give the run at least 1 GB; 2 GB is the sweet spot, and more does not make it faster.
- **Pricing** — pay-per-event. You only pay for rows actually produced. The actor reads your spending limit and remaining account balance before it starts, processes exactly what the budget covers, and never overruns it.

***

### Support

**Need help or want a feature added?**

Contact Support at **<https://docs.google.com/forms/d/e/1FAIpQLSfsKyzZ3nRED7mML47I4LAfNh_mBwkuFMp1FgYYJ4AkDRgaRw/viewform?usp=dialog>** — Fill out this quick form.

We respond quickly and are happy to add new fields or custom integrations.

***

### Tags

image compressor, bulk image compression, compress images online, image optimizer, image optimization api, reduce image file size, shrink images, jpeg compressor, jpg compression, png compressor, compress png, webp compressor, gif compressor, tiff compressor, avif compressor, heic compressor, svg optimizer, svgo, mozjpeg, pngquant, libimagequant, lossless image compression, lossy image compression, pixel perfect compression, batch image compressor, bulk image optimizer, image compression api, compress images from url, image cdn optimization, reduce bandwidth costs, core web vitals, page speed optimization, image seo, website performance, ecommerce image optimization, product photo optimization, shopify image compression, wordpress image optimization, strip exif metadata, remove image metadata, image resizing alternative, apify actor, image processing api, bulk media optimization, zip download images, compress image batch, web image optimization, faster website images

***

*Built with care by One Scales Inc.*

# Actor input Schema

## `imageUrls` (type: `array`):

Enter one or more direct image URLs to compress. Supports JPEG, PNG, WebP, GIF, TIFF, AVIF, HEIC and SVG. The file type is detected from the image itself, so the URL does not need a file extension.

## `compressionType` (type: `string`):

Lossy gives much smaller files at quality 85 — visually indistinguishable for almost every use. Lossless guarantees every pixel is unchanged and is verified before the file is written, so savings are smaller but the image is byte-for-byte identical in appearance.

## `proxyConfiguration` (type: `object`):

Proxy settings for downloading the images. Residential proxies reduce blocking on hosts that rate-limit or geo-restrict image requests. Compression itself runs locally and is unaffected.

## Actor input object example

```json
{
  "imageUrls": [
    "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Fronalpstock_big.jpg/1280px-Fronalpstock_big.jpg",
    "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png",
    "https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg"
  ],
  "compressionType": "lossy",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}
```

# Actor output Schema

## `compressedImages` (type: `string`):

All images with original size, compressed size, bytes saved, percent saved, encoder used, and download URL

## `zipArchive` (type: `string`):

A single zip archive containing every image that compressed successfully — the easiest way to download the whole run at once

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "imageUrls": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Fronalpstock_big.jpg/1280px-Fronalpstock_big.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png",
        "https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg"
    ],
    "compressionType": "lossy",
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ]
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("onescales/image-compressor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "imageUrls": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Fronalpstock_big.jpg/1280px-Fronalpstock_big.jpg",
        "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png",
        "https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg",
    ],
    "compressionType": "lossy",
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
    },
}

# Run the Actor and wait for it to finish
run = client.actor("onescales/image-compressor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "imageUrls": [
    "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Fronalpstock_big.jpg/1280px-Fronalpstock_big.jpg",
    "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png",
    "https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg"
  ],
  "compressionType": "lossy",
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ]
  }
}' |
apify call onescales/image-compressor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,onescales/image-compressor"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/yKnslg3Uvjuqu47AB/builds/zeABYQu5v58FMdbZx/openapi.json
