# Image Converter & Compressor – HEIC, AVIF, WebP, JPG, PNG (`oldjard/image-converter-compressor`) Actor

Convert and compress images in bulk: HEIC to JPG (iPhone), AVIF, WebP, JPEG, PNG, GIF, TIFF, SVG in; WebP, AVIF, JPEG, PNG, GIF or TIFF out. Resize, strip EXIF/GPS, compress to a target size in KB, keep animations, ZIP. From URLs, a dataset or uploaded files. Failed images are free.

- **URL**: https://apify.com/oldjard/image-converter-compressor.md
- **Developed by:** [Joshua White](https://apify.com/oldjard) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.50 / 1,000 image converteds

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/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 Converter & Compressor – HEIC, AVIF, WebP, JPG, PNG

Convert and compress images in bulk. Give it image URLs, a scraper's dataset or files in a key-value store, pick a
format, and get back smaller files with a download link for each one.

- **Reads:** JPEG, PNG, WebP, AVIF, **HEIC/HEIF (iPhone photos)**, GIF, TIFF, BMP and SVG.
- **Writes:** WebP, **AVIF**, JPEG, PNG (lossless or palette-compressed), GIF and TIFF. Or "same as input" to just compress.
- **Compress to a size:** "under 100 KB" finds the highest quality that fits, and shrinks the image only if it must.
- **Resize:** max width/height, crop to fill (thumbnails), pad, or stretch.
- **Strip EXIF and GPS** location data. Photos are turned upright first, so portrait shots stay portrait.
- **Animated GIF and WebP** stay animated when the output is WebP or GIF.
- **ZIP** of every converted file, if you want one.
- **Failed images are free**: broken links, non-images and files that are too big cost nothing.

**Try it:** the input is prefilled with three images (a JPEG photo, a PNG with transparency and an iPhone HEIC).
Click Start and the WebP files are ready in a few seconds.

### How to convert images in bulk

1. Paste image URLs, one per line. Google Drive and Dropbox share links work.
2. Or point it at a **dataset** (the output of any scraper) and name the field with the image URLs, e.g. `images` or
   `product.images`. Lists of URLs and lists of `{ "url": … }` objects both work.
3. Or upload files to a **key-value store** in the Apify Console and give its ID or name.
4. Pick the output format and options, then click **Start**.
5. Open the **Images** table: every row has a link to the converted file. The run's key-value store holds all files,
   and `images.zip` if you turned the ZIP on.

### Which format should I pick?

| Format | Best for | Notes |
|---|---|---|
| **WebP** | Websites, shops, CMS uploads | Works in every current browser. Smaller than JPEG at the same look, and keeps transparency and animation. |
| **AVIF** | The smallest photos | About half the size of WebP for photos. Supported by current browsers; older apps may not open it. |
| **JPEG** | Anything that must open everywhere | Email, marketplaces, print shops. No transparency: transparent areas get the background colour. |
| **PNG** | Logos, screenshots, graphics | Lossy by default (palette, like TinyPNG): in our test a 225 KB transparent PNG became 53 KB. Turn on **Lossless** for exact pixels. |
| **Same as input** | Just compress | JPEG stays JPEG, PNG stays PNG. HEIC becomes JPEG, SVG and BMP become PNG. |

### HEIC to JPG

iPhones save photos as HEIC. Many websites, shops and Windows apps can't open them. Set the format to **JPEG** (or
WebP) and give the HEIC links or files: each photo comes out as a normal JPEG, upright, with the GPS location removed.
Many other converters skip HEIC because the usual Linux image libraries can't read it; this one decodes it.

### What you get for each image

| Field | What it is |
|---|---|
| `url` | Link to the converted file (in the run's key-value store). |
| `key` | The file's name in the key-value store, e.g. `IMG_0412.jpg`. |
| `status` | `ok` or `failed`. |
| `inputFormat`, `outputFormat` | The real format of the source (read from the file itself, not the extension) and the output format. |
| `inputBytes`, `outputBytes`, `savedPercent` | File sizes before and after, and how much smaller the new file is. |
| `inputWidth`, `inputHeight`, `outputWidth`, `outputHeight` | Pixel sizes before and after. |
| `frames` | Frames kept (1 unless an animation stayed animated). |
| `quality` | The quality used. With a target size, the quality that fit. |
| `hitTarget` | With a target size: `true` if the file fits under it. |
| `note` | Anything worth knowing, e.g. "animated input: first frame only". |
| `errorCode`, `error` | Why an image failed, in plain words. Failed rows are free. |
| `source`, `index` | The input URL or key, and its position in your list. |

The run's `OUTPUT` record has the totals: converted, failed, bytes saved, errors by type and the ZIP link.

### How much does it cost?

**$1.50 per 1,000 images** up to 16 megapixels each, which covers phone photos (12 MP), 4K images and almost every
web image. Bigger files count once per started 16 MP: a 24 MP camera photo counts twice, a 46 MP one three times.
Failed images are free. Apify's $5 monthly free credit covers about 3,000 images.

Set a **maximum cost** on the run and it stops cleanly when it's reached: it never converts an image it can't charge
for.

### Input example

```json
{
    "imageUrls": [
        { "url": "https://example.com/photos/IMG_0412.HEIC" },
        { "url": "https://example.com/products/shoe-red.png" }
    ],
    "format": "webp",
    "quality": 80,
    "maxWidth": 1920,
    "maxHeight": 1920,
    "fit": "inside",
    "targetSizeKb": 0,
    "stripMetadata": true,
    "createZip": true
}
```

Convert a scraper's product images:

```json
{
    "datasetId": "YOUR_DATASET_ID",
    "datasetField": "images",
    "format": "webp",
    "maxWidth": 1200
}
```

### Errors you may see

| `errorCode` | Meaning |
|---|---|
| `HTTP_404`, `HTTP_403`, … | The server answered with that status. |
| `NOT_AN_IMAGE` | The link returned a web page or another file type, not an image. |
| `CORRUPT_IMAGE`, `CONVERT_FAILED` | The file is damaged or cut short. |
| `TOO_LARGE` | The file is over the size limit (100 MB by default, up to 200 MB). |
| `NEEDS_MORE_MEMORY` | A very large image needs more memory than the run has. The message says how much: run again with that memory. |
| `OUTPUT_TOO_LARGE` | WebP can't be bigger than 16,383 px a side. Set a max width or pick JPEG/PNG. |
| `ROBOTS_DISALLOWED` | The site's robots.txt asks automated tools not to download its files. |
| `DNS`, `TIMEOUT`, `CONNECTION`, `TLS` | The site could not be reached. |
| `BLOCKED_ADDRESS` | The link points to a private or local network address. |

### Memory and speed

The default is 2 GB, which handles photos up to about 60 MP as WebP (more as JPEG or PNG), HEIC up to about 40 MP and
AVIF up to about 30 MP. Bigger images fail for free with `NEEDS_MORE_MEMORY` and the memory to use. At 2 GB, typical
web photos (about 3 MP) take about 1 second each, so 1,000 take about 15 minutes. Apify gives more CPU with more memory,
so big batches finish faster at 4 or 8 GB.

### Limits

- Only public images: no logins. The tool respects robots.txt and identifies itself in its user agent.
- Images up to 200 megapixels. SVG files are rendered at their own size.
- HEIC metadata is not carried over (the photo itself is). Multi-image HEIC files (bursts) give the first image.
- Animated AVIF and animated PNG are not written; those outputs take the first frame.

### Use it from code

Run it with the Apify API or the Apify client for JavaScript or Python, then read the dataset for the file links.

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("oldjard/image-converter-compressor").call(run_input={
    "imageUrls": [{"url": "https://example.com/a.heic"}],
    "format": "jpeg",
})
for row in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(row["status"], row.get("url"), row.get("error"))
```

Chain it after a scraper with an Apify integration ("Actor run succeeded" → run this actor with the scraper's
`datasetId`), so new product photos are converted as soon as they're scraped.

# Actor input Schema

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

Direct links to image files: JPEG, PNG, WebP, AVIF, HEIC/HEIF (iPhone photos), GIF, TIFF, BMP or SVG. Google Drive and Dropbox share links are turned into direct downloads.

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

ID or name of an Apify dataset, e.g. the output of a scraper. Image URLs are read from the field below.

## `datasetField` (type: `string`):

A field with one URL, a list of URLs, or a list of objects with url/src. Dot paths work (e.g. "product.images"). Default: url.

## `keyValueStoreId` (type: `string`):

ID or name of an Apify key-value store that holds image files (upload them in the Console). Every record except INPUT/OUTPUT is converted, unless you list keys below.

## `keyValueStoreKeys` (type: `array`):

Record keys to convert from the store above. Leave empty for all.

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

WebP: small and supported everywhere. AVIF: about half the size of WebP for photos. JPEG: works with everything. PNG: lossless or palette-compressed. "Same as input" keeps each file's format (HEIC becomes JPEG, SVG and BMP become PNG).

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

Lower is smaller. Blank = 80 for JPEG/WebP, 50 for AVIF (they look about the same). For PNG it sets the palette quality.

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

Keep every pixel exact (WebP, AVIF, PNG, TIFF). Bigger files. Off: PNG is palette-compressed like TinyPNG.

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

Find the highest quality that fits under this size, and shrink the image if even low quality is too big. 0 = off. Works for JPEG, WebP, AVIF, PNG and GIF.

## `maxWidth` (type: `integer`):

Resize to at most this width. 0 = keep. Aspect ratio is kept unless you pick another fit.

## `maxHeight` (type: `integer`):

Resize to at most this height. 0 = keep.

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

inside: fit within the box, no cropping. cover: fill the box exactly, cropping the edges (thumbnails). contain: fit within the box and pad with the background colour. fill: stretch.

## `enlarge` (type: `boolean`):

Off: images smaller than the box keep their size.

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

Hex colour for transparent areas when the output has no transparency (JPEG), and for padding with fit = contain.

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

Remove EXIF, GPS location and XMP for smaller, private files. Photos are rotated upright first either way.

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

Animated GIF/WebP stay animated when the output is WebP or GIF. Other outputs take the first frame.

## `createZip` (type: `boolean`):

One images.zip with every converted file, linked in the run's OUTPUT.

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

Stop after this many images. 0 = no limit (your run's max cost still applies).

## `maxFileSizeMb` (type: `integer`):

Skip (free) any file larger than this. Up to 200.

## Actor input object example

```json
{
  "imageUrls": [
    {
      "url": "https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=2000&fm=jpg"
    },
    {
      "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
    },
    {
      "url": "https://raw.githubusercontent.com/tigranbs/test-heic-images/master/image4.heic"
    }
  ],
  "datasetField": "url",
  "format": "webp",
  "lossless": false,
  "targetSizeKb": 0,
  "maxWidth": 0,
  "maxHeight": 0,
  "fit": "inside",
  "enlarge": false,
  "background": "#ffffff",
  "stripMetadata": true,
  "keepAnimation": true,
  "createZip": false,
  "maxImages": 0,
  "maxFileSizeMb": 100
}
```

# Actor output Schema

## `images` (type: `string`):

Dataset, one row per image: link to the converted file, formats, sizes, dimensions, and the reason for any failure.

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

The run's key-value store with every converted file (and images.zip if you asked for it).

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

Counts, bytes saved, errors by type, and the ZIP link.

# 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": [
        {
            "url": "https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=2000&fm=jpg"
        },
        {
            "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
        },
        {
            "url": "https://raw.githubusercontent.com/tigranbs/test-heic-images/master/image4.heic"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("oldjard/image-converter-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": [
        { "url": "https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=2000&fm=jpg" },
        { "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png" },
        { "url": "https://raw.githubusercontent.com/tigranbs/test-heic-images/master/image4.heic" },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("oldjard/image-converter-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": [
    {
      "url": "https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=2000&fm=jpg"
    },
    {
      "url": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
    },
    {
      "url": "https://raw.githubusercontent.com/tigranbs/test-heic-images/master/image4.heic"
    }
  ]
}' |
apify call oldjard/image-converter-compressor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,oldjard/image-converter-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/0yH24NolkXlOScWJB/builds/fzGidcpjdocdByvba/openapi.json
