# Image Compression & WebP AVIF Converter (Erdnal Media) (`erdnal_api/erdnal-media-image-optimizer`) Actor

Bulk image compressor and image compression API: convert JPG/PNG to WebP or AVIF from image URLs, resize, set quality, strip metadata, without visible quality loss. Pay only for successful images.

- **URL**: https://apify.com/erdnal_api/erdnal-media-image-optimizer.md
- **Developed by:** [Erdnal](https://apify.com/erdnal_api) (community)
- **Categories:** Developer tools, E-commerce, SEO tools
- **Stats:** 1 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.40 / 1,000 image credits

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Image Compression & WebP AVIF Converter (Erdnal Media)

A bulk image compressor and image compression API for lists of image URLs: convert JPG to WebP, PNG to AVIF, resize,
set the quality and remove metadata, then download the optimized files with a report for every image. The default
quality settings compress images without visible quality loss. You pay only for images that were optimized
successfully.

### What it does

- **Input:** public URLs of JPEG or PNG images, up to 1,000 per run (for example the output of a scraper or an
  export of your product catalog).
- **Conversion:** WebP, AVIF, JPEG or PNG output, with optional resizing (aspect ratio kept by default, smaller
  images never enlarged unless you ask for it) and adjustable quality.
- **Metadata removal:** EXIF, XMP, comments and GPS location are removed by default; the ICC colour profile is kept
  so colours stay correct.
- **Output:** the optimized images in the run's key-value store (`image-0000.webp`, `image-0001.webp`, …) and one
  dataset row per image with the link to the file, its dimensions, the size before and after, the percentage saved
  and the credits charged.
- **Safe input handling:** the real file format is checked (a renamed file is rejected, not trusted), and each image
  is processed in an isolated, resource-limited process.

Example: the demo photo (3000×2000 JPEG, 540 KB) becomes a 1600 px wide WebP of 42 KB, 92 % lighter. Savings
depend on the source image.

### Use cases

- **E-commerce catalogs:** a bulk image optimizer for product photos before importing them into a store or a
  marketplace feed.
- **Websites:** compress images for website pages to reduce page weight.
- **CMS and blogs:** convert JPG to WebP or PNG to AVIF for an existing media library, then re-upload the files.
- **Scraping pipelines:** chain it after a scraper that collects image URLs.

### How to use

1. Paste the image URLs into **Image URLs** (one per line).
2. Choose the output format and, if needed, a maximum width or height.
3. Click **Start**. When the run ends, open the **Output** tab: the table links to each optimized image.

Input example:

```json
{
  "imageUrls": [
    "https://api.erdnal.com/v1/media/samples/demo-photo.jpg"
  ],
  "format": "webp",
  "width": 1600,
  "quality": 80
}
```

| Field | Description | Default |
|---|---|---|
| `imageUrls` | Public `https://` URLs of JPEG or PNG images (1 to 1,000) | — |
| `format` | `webp`, `avif`, `jpeg` or `png` | `webp` |
| `width` / `height` | Maximum size in pixels | original size |
| `quality` | 1 to 100 (ignored for PNG, which is lossless) | WebP 80, AVIF 60, JPEG 82 |
| `keepAspectRatio` | Off: resize to exactly width × height (both required) | on |
| `allowUpscale` | Enlarge images smaller than the requested size | off |
| `keepMetadata` | Keep EXIF/XMP/comments (including GPS location) | off |

### Output example

One dataset row per image:

```json
{
  "index": 0,
  "imageUrl": "https://api.erdnal.com/v1/media/samples/demo-photo.jpg",
  "ok": true,
  "outputKey": "image-0000.webp",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/<store>/records/image-0000.webp",
  "format": "webp",
  "contentType": "image/webp",
  "width": 1600,
  "height": 1067,
  "originalBytes": 539584,
  "outputBytes": 42298,
  "savingsPercent": 92.2,
  "creditsCharged": 1,
  "errorCode": null
}
```

A failed image has `ok: false`, `creditsCharged: 0` and an `errorCode`, and the run goes on with the next image.

### Pricing

Pay per event: **$0.003 per credit**. Apify Store discounts apply to paid Apify plans: 10 % off on Bronze, 15 % on Silver, 20 % on Gold and above. The price of an image depends on the size of the image produced:

| Output size | WebP / JPEG / PNG | AVIF |
|---|---|---|
| up to 3.2 MP (Full HD, 2048 px wide) | 1 credit ($0.003) | 3 credits ($0.009) |
| up to 8.4 MP (4K UHD) | 2 credits ($0.006) | 6 credits ($0.018) |
| up to 16.8 MP | 3 credits ($0.009) | 10 credits ($0.030) |
| up to 25 MP | 4 credits ($0.012) | 15 credits ($0.045) |

A tiny start fee ($0.00005) is charged per run.

A PNG source larger than 8.4 MP adds 2 credits. **Failed images are free** (unreachable URL, unsupported file,
image too large). Resizing to the size you display is cheaper and faster.

The Actor respects your maximum cost per run: before each image, it checks that your remaining budget covers the
highest possible price of that image, and stops otherwise. Setting both width and height lowers that ceiling.

### FAQ

**How do I convert JPG to WebP?**
Put the JPG URLs in the input, keep `format` on `webp` and start the run. WebP gives a good balance between file
size and encoding speed, and current browsers support it.

**How do I convert PNG to AVIF?**
Set `format` to `avif`. AVIF files are often the smallest, but encoding needs more processing, so AVIF costs 3 times
more credits than WebP. Transparency is kept in WebP, AVIF and PNG output; in JPEG it is flattened on a white
background.

**Can I compress images in bulk?**
Yes: up to 1,000 URLs per run, processed one after the other. For larger sets, split them into several runs.

**Is metadata removed?**
Yes, by default: EXIF, XMP, comments and GPS location are removed. The ICC colour profile is kept. Enable
`keepMetadata` to keep them.

**Where are my images processed, and are they kept?**
Images are downloaded and processed by the Image Compression & WebP AVIF Converter API by Erdnal, hosted in the European Union, only to produce the
result. Erdnal does not keep the images of this Actor after the response. The optimized files are stored in your
Apify storage, under your Apify account's data retention.

**Why did an image fail?**
Each failed image has an `errorCode`:

- `image_url_unreachable`: the host could not be reached or returned an error;
- `image_url_redirect`: redirects are not followed, use the final image URL;
- `image_url_forbidden`: only public `https://` URLs on port 443 are accepted;
- `unsupported_format` / `malformed_image`: not a valid JPEG or PNG file;
- `file_too_large`: 15 MB per image at most;
- `too_many_pixels` / `dimensions_too_large`: 25 MP and 10,000 px per side at most;
- `output_too_large`: requested output above 25 MP or 8,000 px per side;
- `avif_requires_batch`: AVIF output above 16.8 MP is not available in this Actor.

### Use it from AI agents (MCP)

AI agents can run this Actor through the Apify MCP server (Claude, Cursor, VS Code, GitHub Copilot, Codex). Add this server URL to your MCP client and sign in with your Apify account when asked:

```
https://mcp.apify.com?tools=erdnal_api/erdnal-media-image-optimizer
```

The agent sees the input and output schemas, runs the Actor and reads the results; runs are billed per event, like a normal run.

### Integrations

- **API:** start runs and read results with the Apify API or the Apify clients for JavaScript and Python.
- **Make, Zapier, n8n:** use the Apify integrations of these tools to run the Actor and send the optimized image
  links to your store, CMS or spreadsheet.
- **Webhooks:** call your own endpoint when a run finishes.

### More from Erdnal

- [PDF to Text & OCR](https://apify.com/erdnal_api/erdnal-documents-text-extraction): extract text from PDFs and scanned images, and turn invoices and receipts into JSON.
- Published tasks of this Actor: ready-made presets such as JPG to WebP, PNG to AVIF, Shopify image compression, thumbnails, email images and EXIF/GPS removal (see the **Examples** tab).

### Support

support@erdnal.com — include the `requestId` of the image concerned. See the Image Compression & WebP AVIF Converter terms of use and
privacy policy.

# Actor input Schema

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

Public https:// URLs of the JPEG or PNG images to compress, one per line (1 to 1,000 per run, 15 MB per image). Use the final image URL: redirects are not followed. Example: the image links exported from your store or collected by a scraper.

## `format` (type: `string`):

Output format. WebP (default): the best balance of file size, speed and browser support. AVIF: the smallest files, but slower to encode, so it costs 3 times more credits. JPEG: for email newsletters and old software. PNG: lossless, for logos and screenshots.

## `width` (type: `integer`):

Maximum width in pixels. The image is scaled down to fit (aspect ratio kept) and never enlarged unless you allow it. Leave empty to keep the original size. Tip: use the width at which the image is displayed (e.g. 1600 for a full-width web image): smaller outputs are lighter and cost fewer credits.

## `height` (type: `integer`):

Maximum height in pixels, used like width. Setting both width and height makes the image fit inside that box, and also caps the maximum price per image. Leave empty to keep the original size.

## `quality` (type: `integer`):

Compression quality from 1 to 100: lower means smaller files with more visible artefacts. Leave empty for tuned defaults: WebP 80, AVIF 60, JPEG 82 (good visual quality for the web). Ignored for PNG, which is lossless.

## `keepAspectRatio` (type: `boolean`):

On (default): the image keeps its proportions and fits inside width × height. Off: the image is resized to exactly width × height (both required), which stretches it if the proportions differ; it is not cropped.

## `allowUpscale` (type: `boolean`):

Off (default): images smaller than the requested width or height are left at their size, so quality is never degraded by enlarging. On: small images are enlarged to the requested size.

## `keepMetadata` (type: `boolean`):

Off (default): EXIF, XMP and comments are removed, including the GPS location of phone photos, for privacy and smaller files. On: keep them (for example to preserve copyright or camera data). The ICC colour profile is always kept, so colours stay correct.

## Actor input object example

```json
{
  "imageUrls": [
    "https://api.erdnal.com/v1/media/samples/demo-photo.jpg"
  ],
  "format": "webp",
  "width": 1600,
  "keepAspectRatio": true,
  "allowUpscale": false,
  "keepMetadata": false
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items, overview view: source URL, optimized image URL, dimensions, sizes, saving, credits, error code.

# 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://api.erdnal.com/v1/media/samples/demo-photo.jpg"
    ],
    "width": 1600
};

// Run the Actor and wait for it to finish
const run = await client.actor("erdnal_api/erdnal-media-image-optimizer").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://api.erdnal.com/v1/media/samples/demo-photo.jpg"],
    "width": 1600,
}

# Run the Actor and wait for it to finish
run = client.actor("erdnal_api/erdnal-media-image-optimizer").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://api.erdnal.com/v1/media/samples/demo-photo.jpg"
  ],
  "width": 1600
}' |
apify call erdnal_api/erdnal-media-image-optimizer --silent --output-dataset

```

## MCP server setup

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

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/Gv97mPSePtLuOXqzr/builds/IDTfUlTEWvCNxrvve/openapi.json
