# Image Optimizer & Converter: Website Images to WebP, AVIF (`pikoulas/image-converter`) Actor

Compress and convert images to WebP, AVIF, JPEG, PNG or GIF: from URLs, every image a web page shows, or a scraper's dataset. Under a target size in KB, fitted, cropped or padded to an exact size, EXIF and GPS removed, HEIC read, a ZIP of all. Failures are free.

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

## Pricing

from $2.00 / 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.
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 Optimizer & Converter: Website Images to WebP, AVIF

Give it images, the web pages that show them, or a scraper's dataset, and get each image back converted, resized and
compressed:

- **From anywhere:** image URLs; every image a web page shows (the largest of each srcset, lazy-loaded ones and the
  social preview image), with its alt text; or the image URLs in your Apify datasets, from any scraper.
- **Into WebP, AVIF, JPEG, PNG or GIF,** or the same format, smaller. From JPEG, PNG, WebP, AVIF, HEIC (iPhone photos),
  GIF, TIFF or BMP, up to 50 MB and 100 megapixels each.
- **Under a target file size,** such as 100 KB: the highest quality that fits, and a smaller image if even the lowest
  doesn't.
- **Resized** to fit inside a width and height, or to an exact size: **cover** crops the overflow, **pad** keeps the
  whole image on a background colour, as shops want square product photos.
- **Animations stay animated** from GIF, WebP, PNG or AVIF into WebP, AVIF, PNG or GIF.
- **EXIF and GPS removed,** the photo turned upright first. The colour profile is kept.
- **A link to each file,** its size before and after and what was saved, the page it was on, and all files in one ZIP
  if you want. The run's status says what the whole set weighed before and after.

It costs **$2 per 1,000 images** on Apify's paid plans and $3 on the free plan. An image that can't be fetched or
read costs nothing.

### What people use it for

- **Faster websites:** give your pages and get their images as WebP or AVIF at the width they're shown, with how
  much lighter they get, for Core Web Vitals and PageSpeed.
- **E-commerce and marketplaces:** product photos at the exact size and under the file size a marketplace asks for,
  padded on white.
- **After a scraper:** pick its dataset, and the images it found come out converted, ready for your site or feed.
- **iPhone photos:** HEIC into JPEG or WebP that every browser and tool opens.
- **Privacy:** photos without their GPS position and camera details before they're published.
- **Automation:** image conversion as one step of a Make, Zapier or n8n workflow.

### How to convert images

1. Click **Try for free**; Apify's free plan covers a first run.
2. Enter **Image URLs**, **Web pages** or **Apify datasets**, or a mix.
3. Pick the format under **Convert to**, and a **Max file size**, **Width** or **Height** if you want them smaller.
4. Click **Start**, then open the files from the **Output** tab, or download the dataset as JSON, CSV or Excel.

An input with every option:

```json
{
  "urls": [
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic"
  ],
  "pageUrls": ["https://www.example.com/blog/"],
  "maxImagesPerPage": 100,
  "datasetIds": ["YOUR_DATASET_ID"],
  "urlFields": ["imageUrl"],
  "format": "webp",
  "quality": 80,
  "maxKilobytes": 150,
  "maxWidth": 1600,
  "maxHeight": 1600,
  "fit": "inside",
  "minSide": 50,
  "background": "#ffffff",
  "zip": true
}
```

For a shop's square product photos under 100 KB:

```json
{
  "datasetIds": ["YOUR_DATASET_ID"],
  "format": "jpeg",
  "maxKilobytes": 100,
  "maxWidth": 1000,
  "maxHeight": 1000,
  "fit": "pad",
  "background": "#ffffff"
}
```

### Output

```json
{
  "url": "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
  "foundOn": null,
  "alt": null,
  "finalUrl": "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
  "fileName": "sample-photo.jpg",
  "imageUrl": "https://api.apify.com/v2/key-value-stores/ZGJnCDiBab3DLzD5M/records/00000-sample-photo.webp?signature=13PIcFjmSe6VApfnVxQeN",
  "key": "00000-sample-photo.webp",
  "originalFormat": "JPEG",
  "format": "webp",
  "originalWidth": 3000,
  "originalHeight": 2000,
  "width": 1600,
  "height": 1067,
  "frames": 1,
  "quality": 80,
  "withinMaxSize": null,
  "megapixels": 6.0,
  "originalBytes": 2858759,
  "sizeBytes": 41696,
  "savedPercent": 98.5,
  "convertedAt": "2026-11-09T10:18:47Z",
  "error": null
}
```

`imageUrl` opens the file as long as the run's storage is kept; `key` names it in the run's key-value store, where
`images.zip` holds them all when **ZIP of all files** is on. `savedPercent` is below zero when the new file is larger,
as a GIF's can be in another format. `foundOn` is the page or dataset an image came from, `alt` its alt text on the
page, and `quality` what a lossy format was saved at. With a **Max file size**, `withinMaxSize` is false for the rare
image that's over it even at a fifth of its size, or at the exact size **cover** and **pad** keep. An image, page or
dataset that can't be read comes with `url` and `error`, saying why.

### Use it as an API

Apify's API starts a run and returns its dataset as JSON; its Python and JavaScript clients, and
its Make, Zapier and n8n integrations, work the same way.

```bash
curl -X POST "https://api.apify.com/v2/acts/pikoulas~image-converter/run-sync-get-dataset-items?token=YOUR_APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic"], "format": "jpeg"}'
```

AI agents can call it as a tool through Apify's MCP server: `https://mcp.apify.com?tools=pikoulas/image-converter`.

### How much does it cost?

An image is $0.002, whatever the format; reading pages and datasets, images left out as too small, and the ZIP
are free. One over 16 megapixels counts once per started 16, so
a 24 MP photo is two and a 48 MP one three; an animation counts all its frames. A thousand web images cost $2. Set a
spending limit on a run and it stops there, with what it has converted so far.

### Good to know

- **Quality** goes from 1 to 100 for WebP, AVIF and JPEG; 80 is a good start for photos. PNG and GIF are lossless and
  only compressed, so a photo as PNG grows.
- **Transparency** is kept in WebP, AVIF, PNG and GIF. JPEG has none, so transparent parts take the **Background** colour.
- **Pages:** an image on several pages is converted once. SVG and icons are left out, since they aren't photos to
  convert, and so is any image under **Skip images smaller than**, as tracking pixels.
- Of a TIFF with several pages or a HEIC burst, only the first image is converted, as is an animation's first frame
  in JPEG.
- **More memory is faster:** one image at a time per GB of memory, up to eight. A 6 MP photo takes about 9 seconds
  at 1 GB.
- **The ZIP holds up to 300 MB;** past that, the remaining files are in the store alone.
- **A site's refusal is respected.** It names itself in its User-Agent and reads each site's `robots.txt`, one request
  a second per site at most. A path `robots.txt` refuses isn't fetched, and a site that answers 401, 403 or 451, shows a
  verification page or answers 429 twice is left alone for the rest of the run; the rest of your list goes on. It uses
  no proxy and doesn't try to get past any of this, so an image behind a check comes back with an `error`.
- Only public addresses are fetched, not private networks.
- **Contact.** The Actor keeps nothing itself: each image stays on disk only while it's being converted, and files and
  results sit in the storage of whoever ran it. Questions or requests go to spyridwn.pd@gmail.com.
- Converts with Pillow, libavif and libheif.

### FAQ

#### Is it legal to convert images from other websites?

It fetches only the images you point it at, the pages you give it and the images those pages show, as anyone could
open them, without logging in, and it keeps to each site's `robots.txt`. You are responsible for having the right to use them: images are usually someone's copyrighted
work, converting one doesn't change who owns it, a site's terms may limit how you use what it publishes, and people
shown in photos are protected by laws such as the GDPR and the CCPA. If you're unsure, ask a lawyer; Apify's
[Is web scraping legal?](https://blog.apify.com/is-web-scraping-legal/) is a good start.

#### Can I convert images from my computer?

It reads URLs, pages and datasets. An image you can reach only from your own computer needs a public address first, such as a record in
an Apify key-value store with public read access, or a link from your own storage.

#### Something missing or not working?

Open an issue on the **Issues** tab with the input you used, or ask there for a field you need.

If it does what you need, a review on the **Reviews** tab helps others find it.

# Actor input Schema

## `urls` (type: `array`):

Addresses of images: JPEG, PNG, WebP, AVIF, HEIC, GIF, TIFF or BMP, up to 50 MB and 100 megapixels each. One over 16 megapixels counts as an image per started 16.

## `pageUrls` (type: `array`):

Pages whose images to convert: each one they show (the largest of a srcset, lazy-loaded ones too) and their social preview image, with its alt text. SVG and icons are left out. Reading a page is free.

## `maxImagesPerPage` (type: `integer`):

The first this many images of each page.

## `datasetIds` (type: `array`):

Datasets from your account, a scraper's results say, whose image URLs to convert.

## `urlFields` (type: `array`):

Fields holding an image URL or a list of them, like imageUrl or images, nested ones by dotted path. Empty: every URL in each row that ends in an image's extension.

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

The format of the files you get. Original keeps JPEG, PNG, WebP, AVIF and GIF as they are and turns the rest (HEIC, TIFF, BMP) into JPEG.

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

For WebP, AVIF and JPEG: lower makes smaller files. PNG and GIF are lossless and only compressed.

## `maxKilobytes` (type: `integer`):

Each file at most this size: WebP, AVIF and JPEG take the highest quality that fits, and an image still over it at quality 10 (or a PNG or GIF over it) is shrunk until it fits.

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

Images wider than this are scaled down to it, keeping their proportions; smaller ones aren't enlarged. With Fit cover or pad, the exact width.

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

Images taller than this are scaled down to it, keeping their proportions; smaller ones aren't enlarged. With Fit cover or pad, the exact height.

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

How an image meets the width and height. Cover and pad need both, and make every image that size, as a shop's square product photos.

## `minSide` (type: `integer`):

Images whose width or height is under this, as icons and tracking pixels, are left out and not charged.

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

What transparent parts become in a JPEG, which has no transparency, and the margins of Fit pad: a colour such as #ffffff or black.

## `zip` (type: `boolean`):

Also puts every converted file in one images.zip, up to 300 MB, at no extra cost.

## Actor input object example

```json
{
  "urls": [
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic"
  ],
  "maxImagesPerPage": 10,
  "format": "webp",
  "quality": 80,
  "fit": "inside",
  "background": "#ffffff",
  "zip": false
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `files` (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 = {
    "urls": [
        "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
        "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic"
    ],
    "maxImagesPerPage": 10
};

// Run the Actor and wait for it to finish
const run = await client.actor("pikoulas/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 = {
    "urls": [
        "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
        "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic",
    ],
    "maxImagesPerPage": 10,
}

# Run the Actor and wait for it to finish
run = client.actor("pikoulas/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 '{
  "urls": [
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.jpg",
    "https://api.apify.com/v2/key-value-stores/QOCeroT733vQ3tPPv/records/sample-photo.heic"
  ],
  "maxImagesPerPage": 10
}' |
apify call pikoulas/image-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,pikoulas/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/aShr0xaDrfKIigbs5/builds/5pk3yt8KiIKGcuKdc/openapi.json
