# Image Converter & Optimizer (WebP, AVIF, JPEG, PNG) (`cellwright/image-converter`) Actor

Bulk-convert and compress images from URLs or a dataset to WebP, AVIF, JPEG or PNG. Resize, crop, fix orientation, strip metadata, hit a target file size. Failed images are free.

- **URL**: https://apify.com/cellwright/image-converter.md
- **Developed by:** [Cellwright](https://apify.com/cellwright) (community)
- **Categories:** Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per event

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/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 Converter & Optimizer (WebP, AVIF, JPEG, PNG)

Convert and compress images **in bulk** – from a list of URLs or straight from the dataset of another Actor (product, listing or real-estate scrapers). Output **WebP, AVIF, JPEG or PNG**, resize or crop to exact thumbnails, fix camera orientation, strip EXIF/GPS metadata and even hit a **target file size**. One file and one clean record per image. **Failed images are free.**

Ideal for web performance (Core Web Vitals, PageSpeed), e-commerce image pipelines, CMS migrations, thumbnail generation and AI agents that need small, consistent images.

### Why this Actor

- **Modern formats:** WebP and AVIF (typically 30–80 % smaller than JPEG/PNG), plus JPEG, PNG, GIF or "keep original format".
- **Chain it after a scraper:** pick a dataset and the Actor finds the image field itself (`imageUrl`, `image`, `images[]`, `url`, `src`, …) or use your own field path (`product.image`).
- **Resize the way you need:** *inside* (keep aspect ratio, never upscale by default), *cover* (exact size, cropped – thumbnails), *contain* (exact size, padded with a colour or transparency).
- **Target file size:** e.g. "every image ≤ 100 kB" – the quality is lowered step by step, never below your minimum.
- **Correct by default:** EXIF orientation applied (no sideways photos), colour profile kept, transparency kept (flattened onto your background colour for JPEG), animated GIF/WebP stay animated, CMYK and 16-bit images handled.
- **Privacy:** EXIF data such as GPS location and camera serials are removed unless you want to keep them.
- **Fair and safe:** pay only for converted images; download errors, 404s and non-images are free. Private/internal addresses are blocked.

### Input

| Field | Default | Description |
|---|---|---|
| `images` | – | Direct image URLs (JPEG, PNG, GIF, WebP, AVIF, BMP, TIFF, ICO), max 50 MB each |
| `datasetId` | – | Optional: take image URLs from a dataset (combined with `images`) |
| `urlField` | auto | Dataset field with the URL or a list of URLs; dot path allowed |
| `format` | `webp` | `webp`, `avif`, `jpeg`, `png`, `gif`, `original` |
| `quality` | `80` | 1–100 for WebP, AVIF, JPEG |
| `width`, `height` | `0` | Max size (`inside`) or exact size (`cover`/`contain`); 0 = keep |
| `fit` | `inside` | `inside`, `cover`, `contain` |
| `upscale` | `false` | Enlarge smaller images with `inside` |
| `background` | `#ffffff` | Flatten/pad colour, or `transparent` |
| `targetSizeKb` | `0` | Max file size in kB (lossy formats), 0 = off |
| `minQuality` | `40` | Lowest quality for the target-size search |
| `lossless` | `false` | Lossless WebP/AVIF (logos, screenshots) |
| `stripMetadata` | `true` | Remove EXIF/GPS |
| `keepColorProfile` | `true` | Keep ICC profile |
| `keepAnimation` | `true` | Keep animations (max 300 frames) |
| `progressive` | `true` | Progressive JPEG |
| `maxImages` | `1000` | Budget guard per run |
| `maxConcurrency` | `4` | Parallel downloads (1–16) |

Example – product thumbnails from a scraper dataset:

```json
{
  "datasetId": "YOUR_DATASET_ID",
  "format": "webp",
  "width": 600,
  "height": 600,
  "fit": "contain",
  "background": "#ffffff",
  "targetSizeKb": 60
}
```

### Output

Converted files are stored in the run's key-value store (keys like `0001-product-photo.webp`). One dataset record per image:

| Field | Description |
|---|---|
| `sourceUrl` | Image URL from the input |
| `ok` | `false` if the image could not be converted (then free) |
| `key`, `outputUrl` | Key-value store key and download URL of the converted file |
| `format`, `contentType` | Output format and MIME type |
| `width`, `height`, `frames` | Output size and number of frames |
| `outputBytes`, `originalBytes`, `savedBytes`, `savedPercent` | File sizes and savings |
| `originalFormat`, `originalWidth`, `originalHeight`, `originalFrames` | Source image |
| `quality`, `lossless` | Quality used (after a target-size search) |
| `targetSizeReached` | `true`/`false` with `targetSizeKb`, else `null` |
| `hasAlpha`, `outputMegapixels` | Transparency, output megapixels (all frames) |
| `error`, `errorType` | Reason if `ok` is `false`: `input`, `http`, `network`, `blocked` |
| `processedAt` | ISO timestamp |

Dataset views: **Images** (with preview) and **Details**. A run summary (images converted/failed, total savings) is in the key-value store record `OUTPUT`.

### Pricing (pay per event)

- **$0.001 per converted image** (up to 10 megapixels of output)
- Very large or animated outputs count once per started 10 MP (width × height × frames), e.g. a 24 MP photo without resizing = 3 events
- Free: download errors, 404s, non-images, files over the limits

Example: 1,000 product photos resized to 1200 px WebP = $1.00.

### Limits

- Max 50 MB per file, 100 megapixels input, 40 megapixels output per frame, 300 animation frames.
- No HEIC/HEIF input yet, no SVG rasterising.
- Public URLs only (no logins, cookies or custom headers). Process only images you are allowed to use.

### Use with AI agents / API

Flat, stable camelCase fields; run via the Apify API or MCP server, read the dataset and download `outputUrl`.

# Actor input Schema

## `images` (type: `array`):

Direct URLs of the images to convert (JPEG, PNG, GIF, WebP, AVIF, BMP, TIFF, ICO). One output file and one dataset row per image. Max 50 MB per file.

## `datasetId` (type: `string`):

Optional. Take image URLs from a dataset, e.g. the output of a product or listing scraper. Combined with 'Image URLs'.

## `urlField` (type: `string`):

Field of the dataset items that holds the image URL or a list of URLs (dot path allowed, e.g. 'product.image'). Empty = auto-detect imageUrl, image, url, src, imageUrls, images, thumbnailUrl, photo.

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

Target format. WebP: best all-rounder for websites. AVIF: smallest files, slower. JPEG: maximum compatibility (no transparency). PNG: lossless. 'original' keeps the format and only resizes/compresses.

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

Quality for WebP, AVIF and JPEG (1–100). 75–85 is visually lossless for most photos.

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

Maximum width (fit 'inside') or exact width (fit 'cover' / 'contain'). 0 = keep.

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

Maximum height (fit 'inside') or exact height (fit 'cover' / 'contain'). 0 = keep.

## `fit` (type: `string`):

inside: scale down to fit within width/height, keep aspect ratio. cover: fill exactly width x height, crop the overflow (thumbnails). contain: fit inside width x height and pad with the background colour.

## `upscale` (type: `boolean`):

With fit 'inside': also enlarge images smaller than width/height. Off by default.

## `background` (type: `string`):

Hex colour used to flatten transparency for JPEG and to pad in 'contain' mode, e.g. #ffffff. 'transparent' pads with transparency (WebP, AVIF, PNG).

## `targetSizeKb` (type: `integer`):

Optional. For WebP, AVIF and JPEG: lower the quality step by step (not below 'Minimum quality') until the file is at most this size. 0 = off.

## `minQuality` (type: `integer`):

Lowest quality the target-size search may use.

## `lossless` (type: `boolean`):

Encode WebP/AVIF without quality loss (larger files; good for logos, screenshots, graphics).

## `stripMetadata` (type: `boolean`):

Remove EXIF data such as camera details and GPS location. The orientation is always applied to the pixels first, so images never end up rotated.

## `keepColorProfile` (type: `boolean`):

Keep the embedded ICC colour profile so colours look the same (recommended).

## `keepAnimation` (type: `boolean`):

Animated GIF/WebP/APNG stay animated when the output format supports it (WebP, AVIF, PNG, GIF). Off = first frame only. Max 300 frames.

## `progressive` (type: `boolean`):

Write progressive JPEGs (load gradually in browsers, usually slightly smaller).

## `maxImages` (type: `integer`):

Upper limit of images processed in this run (protects your budget when reading a large dataset).

## `maxConcurrency` (type: `integer`):

How many images are downloaded at the same time.

## Actor input object example

```json
{
  "images": [
    {
      "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
    }
  ],
  "format": "webp",
  "quality": 80,
  "width": 0,
  "height": 0,
  "fit": "inside",
  "upscale": false,
  "background": "#ffffff",
  "targetSizeKb": 0,
  "minQuality": 40,
  "lossless": false,
  "stripMetadata": true,
  "keepColorProfile": true,
  "keepAnimation": true,
  "progressive": true,
  "maxImages": 1000,
  "maxConcurrency": 4
}
```

# Actor output Schema

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

One item per processed input in the default dataset (JSON, CSV, Excel via the dataset export).

## `summary` (type: `string`):

Totals and statistics of the run (OUTPUT record).

## `files` (type: `string`):

Generated files in the default key-value store (each dataset item links its file).

# 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 = {
    "images": [
        {
            "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("cellwright/image-converter").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 = { "images": [{ "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" }] }

# Run the Actor and wait for it to finish
run = client.actor("cellwright/image-converter").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 '{
  "images": [
    {
      "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
    }
  ]
}' |
apify call cellwright/image-converter --silent --output-dataset

```

## MCP server setup

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

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/RWCQ65Bq5MsGykhZd/builds/XXJzoRcLdRt3VRGVh/openapi.json
