# Image Format Converter (`jungle_synthesizer/image-format-converter`) Actor

Converts images between PNG, JPEG, WEBP, and AVIF, with optional resize, aspect-ratio fit, and quality control. Accepts image URLs or inline data: URIs; returns one record per image with the converted file's download link and dimensions.

- **URL**: https://apify.com/jungle_synthesizer/image-format-converter.md
- **Developed by:** [BowTiedRaccoon](https://apify.com/jungle_synthesizer) (community)
- **Categories:** Developer tools, Other
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.80 / 1,000 record scrapeds

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 Format Converter

Convert images between PNG, JPEG, WEBP, and AVIF, with optional resize, aspect-ratio fit, and quality control. Point it at image URLs or inline `data:` URIs and get back one record per image with the converted file's download link and dimensions.

***

### What this actor does

For each image in your input list, the actor:

1. **Fetches or decodes the source** — a plain `http(s)` URL is downloaded; a `data:` URI (e.g. `data:image/png;base64,...`) is decoded inline, no network round-trip needed
2. **Optionally resizes it** to the width/height you specify, using the fit mode you choose
3. **Re-encodes it** to your target format at the quality level you choose
4. **Saves the converted file** to the run's key-value store and returns a public download link

Every attempted image gets exactly one output record, whether the conversion succeeded or not — a bad URL or an unreadable file shows up as a record with `status: "error"` and a reason, not a crashed run.

**Scope note:** SVG is accepted as a *source* image (it's rasterized before conversion) but is not offered as a target format — turning a raster photo into a true vector SVG needs a tracing algorithm, not a format re-encode, and that isn't what this actor does.

***

### Input

| Field          | Type             | Default  | Description |
|----------------|------------------|----------|---|
| `images`       | array of strings | —        | **Required.** Image sources to convert, one result record per entry. Each is either a direct `http(s)` URL or an inline `data:` URI |
| `targetFormat` | string (enum)    | `webp`   | **Required.** Output format for every converted file: `jpeg`, `png`, `webp`, or `avif` |
| `quality`      | integer          | `80`     | Encode quality 1-100 for lossy formats (`jpeg`, `webp`, `avif`). Ignored for `png`, which is always lossless |
| `resizeWidth`  | integer          | —        | Target width in pixels. Leave blank to keep the source width (or derive it from `resizeHeight`, preserving aspect ratio) |
| `resizeHeight` | integer          | —        | Target height in pixels. Leave blank to keep the source height (or derive it from `resizeWidth`, preserving aspect ratio) |
| `fit`          | string (enum)    | `inside` | How to fit the image when both `resizeWidth` and `resizeHeight` are set: `inside`, `outside`, `cover`, `contain`, or `fill`. Ignored when only one dimension (or neither) is set |
| `smartCrop`    | boolean          | `false`  | When `fit` is `cover`, crop toward the most visually significant region instead of the image center |
| `maxItems`     | integer          | `5`      | Maximum number of images to convert in this run (one record per image, in input order) |

**Example input:**

```json
{
  "images": [
    "https://example.com/photo.jpg",
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
  ],
  "targetFormat": "webp",
  "quality": 80,
  "resizeWidth": 800,
  "resizeHeight": 800,
  "fit": "inside"
}
```

***

### Output

One record per input image, always — success and failure alike.

| Field                | Type    | Description                                                                                 |
|----------------------|---------|---------------------------------------------------------------------------------------------|
| `sourceIndex`        | integer | Position of this image in your `images` array                                               |
| `source`             | string  | The input URL (a `data:` URI is shown as the literal string `"[data URI]"`)                 |
| `status`             | string  | `ok` or `error`                                                                             |
| `errorMsg`           | string  | Why the conversion failed; `null` on success                                                |
| `originalFormat`     | string  | Detected source image format (e.g. `png`, `jpeg`); `null` on failure                        |
| `originalWidth`      | integer | Source image width in pixels; `null` on failure                                             |
| `originalHeight`     | integer | Source image height in pixels; `null` on failure                                            |
| `originalSizeBytes`  | integer | Source image size in bytes; `null` on failure                                               |
| `convertedFormat`    | string  | Output format actually written (matches `targetFormat`); `null` on failure                  |
| `convertedWidth`     | integer | Output image width in pixels after any resize; `null` on failure                            |
| `convertedHeight`    | integer | Output image height in pixels after any resize; `null` on failure                           |
| `convertedSizeBytes` | integer | Output file size in bytes; `null` on failure                                                |
| `downloadUrl`        | string  | Public URL to download the converted file from the run's key-value store; `null` on failure |

**Example output record:**

```json
{
  "sourceIndex": 0,
  "source": "https://example.com/photo.jpg",
  "status": "ok",
  "errorMsg": null,
  "originalFormat": "jpeg",
  "originalWidth": 2400,
  "originalHeight": 1600,
  "originalSizeBytes": 843210,
  "convertedFormat": "webp",
  "convertedWidth": 800,
  "convertedHeight": 533,
  "convertedSizeBytes": 61244,
  "downloadUrl": "https://api.apify.com/v2/key-value-stores/<store-id>/records/converted-0000.webp"
}
```

***

### Limits

Each source image is capped at 15 MB before decoding — comfortably above any ordinary photo or screenshot. A handful of conversions run in parallel per batch, so very large runs process steadily rather than all at once.

***

### Use cases

- **Web/app asset pipelines**: Batch-convert uploaded photos to WEBP/AVIF for smaller page weight
- **Thumbnail generation**: Resize and re-encode a product catalog's images to a consistent size
- **Format normalization**: Standardize a mixed PNG/JPEG/WEBP image set to one target format before downstream processing
- **Inline asset conversion**: Convert a base64-embedded image straight from another tool's output without hosting it first

# Actor input Schema

## `sp_intended_usage` (type: `string`):

What will this data feed? E.g. lead lists, KYB checks, price tracking.

## `sp_improvement_suggestions` (type: `string`):

Provide any feedback or suggestions for improvements.

## `sp_contact` (type: `string`):

We'll personally help with your use case. No spam.

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

Image sources to convert, one result record per entry. Each is either a direct http(s) URL or an inline data: URI (data:image/png;base64,...). SVG is accepted as a SOURCE (rasterized), not as a target format.

## `targetFormat` (type: `string`):

Output image format for every converted file.

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

Encode quality 1-100 for lossy formats (jpeg, webp, avif). Ignored for png, which is always lossless.

## `resizeWidth` (type: `integer`):

Target width in pixels. Leave blank to keep the source width (or derive it from resizeHeight, preserving aspect ratio).

## `resizeHeight` (type: `integer`):

Target height in pixels. Leave blank to keep the source height (or derive it from resizeWidth, preserving aspect ratio).

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

How to fit the image when both resizeWidth and resizeHeight are set. Ignored when only one dimension (or neither) is set.

## `smartCrop` (type: `boolean`):

When Resize Fit is 'cover', crop toward the most visually significant region instead of the image center.

## `maxItems` (type: `integer`):

Maximum number of images to convert in this run (one record per image, in input order). Default 5.

## Actor input object example

```json
{
  "sp_contact": "Share your email here...",
  "images": [
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
  ],
  "targetFormat": "webp",
  "quality": 80,
  "fit": "inside",
  "smartCrop": false,
  "maxItems": 5
}
```

# Actor output Schema

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

No description

# 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 = {
    "sp_contact": "Share your email here...",
    "images": [
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
    ],
    "targetFormat": "webp",
    "quality": 80,
    "maxItems": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("jungle_synthesizer/image-format-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 = {
    "sp_contact": "Share your email here...",
    "images": ["data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="],
    "targetFormat": "webp",
    "quality": 80,
    "maxItems": 5,
}

# Run the Actor and wait for it to finish
run = client.actor("jungle_synthesizer/image-format-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 '{
  "sp_contact": "Share your email here...",
  "images": [
    "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII="
  ],
  "targetFormat": "webp",
  "quality": 80,
  "maxItems": 5
}' |
apify call jungle_synthesizer/image-format-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,jungle_synthesizer/image-format-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/mQrO23VgYkdXJt6J1/builds/URx6ckuvrOgOgLtaf/openapi.json
