# Image Resizer API (`igview-owner/image-resizer-api`) Actor

Professional image resizer API for automated batch image processing. Resize images to any dimensions with smart cropping, format conversion (JPEG, PNG, WebP, TIFF), and quality optimization. Perfect for web optimization, e-commerce thumbnails, social media content, and responsive design.

- **URL**: https://apify.com/igview-owner/image-resizer-api.md
- **Developed by:** [Sachin Kumar Yadav](https://apify.com/igview-owner) (community)
- **Categories:** Automation, Developer tools, E-commerce
- **Stats:** 28 total users, 4 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $1.00 / 1,000 results

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Image Resizer API - Batch Image Processing & Smart Cropping

**Professional Image Resizer API** for automated batch image processing. Resize images to any dimensions with smart cropping, format conversion, and quality optimization. Perfect for web optimization, e-commerce, social media, and responsive design.

### Features

✅ **Multiple Image Formats**: Supports JPEG, PNG, WebP, TIFF  
✅ **Batch Processing**: Handle multiple images simultaneously  
✅ **Smart Cropping**: Intelligent face/subject detection using entropy analysis  
✅ **Flexible Resizing**: Multiple fit modes (cover, contain, fill, inside, outside)  
✅ **Format Conversion**: Convert between different image formats  
✅ **Quality Control**: Customizable compression settings  
✅ **Multiple Input Sources**: URLs, Base64, or Key-Value Store

### Pricing Model

This Actor uses **Pay-per-Event** pricing:

| Event | Cost | Description |
|-------|------|-------------|
| ACTOR_START | $0.01 | Charged once when Actor starts |
| ACTOR_PROCESSING | $0.005 | Charged for each image processed |
| ACTOR_COMPLETE | $0.005 | Charged once when Actor completes |

**Example Cost Calculation:**
- Processing 10 images = $0.01 (start) + $0.05 (10 × processing) + $0.005 (complete) = **$0.065**

### Input Configuration

#### Required Fields

- **images**: Array of image objects with one of:
  - `url`: Direct image URL
  - `base64`: Base64 encoded image data
  - `keyValueStoreKey`: Key from Apify Key-Value Store

#### Optional Fields

- **width**: Target width in pixels (1-10000)
- **height**: Target height in pixels (1-10000)
- **fit**: Resize mode
  - `cover`: Crop to fill dimensions (default)
  - `contain`: Fit within dimensions with letterboxing
  - `fill`: Stretch to exact dimensions
  - `inside`: Resize to fit inside dimensions
  - `outside`: Resize to fit outside dimensions
- **position**: Crop position for 'cover' mode
  - `smart`: Intelligent face/subject detection
  - `center`, `top`, `bottom`, `left`, `right`
- **format**: Output format (`jpeg`, `png`, `webp`, `tiff`)
- **quality**: 1-100 (default: 80)
- **backgroundColor**: RGBA color for letterboxing
- **outputFolder**: Folder name in Key-Value Store (default: "resized-images")

### Example Input

```json
{
  "images": [
    {
      "url": "https://example.com/image1.jpg"
    },
    {
      "url": "https://example.com/image2.png",
      "filename": "custom-name"
    }
  ],
  "width": 800,
  "height": 600,
  "fit": "cover",
  "position": "smart",
  "format": "webp",
  "quality": 85
}
````

### Output

Results are saved to the Dataset with:

```json
{
  "summary": {
    "totalImages": 2,
    "processedSuccessfully": 2,
    "errors": 0,
    "successRate": "100.00%"
  },
  "results": [
    {
      "success": true,
      "originalFilename": "image1.jpg",
      "outputFilename": "resized-images/image1_800x600.webp",
      "publicUrl": "https://api.apify.com/v2/key-value-stores/.../records/...",
      "originalSize": {
        "width": 1920,
        "height": 1080,
        "format": "jpeg",
        "bytes": 245678
      },
      "outputSize": {
        "width": 800,
        "height": 600,
        "format": "webp",
        "bytes": 45230
      },
      "compressionRatio": "81.58%"
    }
  ]
}
```

### Use Cases

#### 🌐 Web Development

Optimize images for responsive websites with multiple breakpoints

#### 🛒 E-commerce

Generate product thumbnails and multiple size variants

#### 📱 Social Media

Resize images for different platform requirements (Instagram, Facebook, Twitter)

#### 📰 Content Management

Batch process uploaded images for blogs and news sites

#### 📲 Mobile Apps

Create app icons and assets in various sizes

### API Integration

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });

const run = await client.actor('YOUR_USERNAME/image-resize-api').call({
  images: [
    { url: 'https://example.com/image.jpg' }
  ],
  width: 800,
  height: 600,
  fit: 'cover',
  format: 'webp',
  quality: 85
});

const dataset = await client.dataset(run.defaultDatasetId).listItems();
console.log(dataset.items[0]);
```

### Smart Cropping

When using `"position": "smart"`, the Actor uses advanced algorithms to detect:

- 👤 Faces
- 🎯 Areas of interest (high contrast/detail)
- 📐 Composition balance

This ensures important subjects stay in frame when cropping.

### Performance Tips

1. **Batch Processing**: Group multiple images in one run to minimize startup costs
2. **WebP Format**: Best compression ratio for web use
3. **Quality Setting**: 80-85 is optimal for most use cases
4. **Smart Cropping**: Only use when needed (adds processing time)

### Support

For issues or questions:

- 📧 Create new issue
- 📖 Check [Apify documentation](https://docs.apify.com)

### License

Apache-2.0

# Actor input Schema

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

Array of images to resize. Each image can be provided as URL, base64, or Key-Value Store key.

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

Target width in pixels. Leave empty for auto-scaling based on height.

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

Target height in pixels. Leave empty for auto-scaling based on width.

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

How the image should be resized to fit the dimensions.

## `position` (type: `string`):

Position for cropping (when fit is 'cover'). Use 'smart' for intelligent face/subject detection.

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

Output image format. Leave empty to keep original format.

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

Output quality (1-100). Higher values mean better quality but larger file size.

## `outputFolder` (type: `string`):

Folder name in Key-Value Store for output images

## Actor input object example

```json
{
  "images": [
    {
      "url": "https://images.unsplash.com/photo-1506748686214-e9df14d4d9d0"
    }
  ],
  "width": 800,
  "height": 600,
  "fit": "cover",
  "position": "center",
  "quality": 80,
  "outputFolder": "resized-images"
}
```

# 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://images.unsplash.com/photo-1506748686214-e9df14d4d9d0"
        }
    ],
    "width": 800,
    "height": 600
};

// Run the Actor and wait for it to finish
const run = await client.actor("igview-owner/image-resizer-api").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://images.unsplash.com/photo-1506748686214-e9df14d4d9d0" }],
    "width": 800,
    "height": 600,
}

# Run the Actor and wait for it to finish
run = client.actor("igview-owner/image-resizer-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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://images.unsplash.com/photo-1506748686214-e9df14d4d9d0"
    }
  ],
  "width": 800,
  "height": 600
}' |
apify call igview-owner/image-resizer-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=igview-owner/image-resizer-api",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Image Resizer API",
        "description": "Professional image resizer API for automated batch image processing. Resize images to any dimensions with smart cropping, format conversion (JPEG, PNG, WebP, TIFF), and quality optimization. Perfect for web optimization, e-commerce thumbnails, social media content, and responsive design.",
        "version": "1.0",
        "x-build-id": "5MVDuzrP37Ksf9vdJ"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/igview-owner~image-resizer-api/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-igview-owner-image-resizer-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/igview-owner~image-resizer-api/runs": {
            "post": {
                "operationId": "runs-sync-igview-owner-image-resizer-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/igview-owner~image-resizer-api/run-sync": {
            "post": {
                "operationId": "run-sync-igview-owner-image-resizer-api",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "images"
                ],
                "properties": {
                    "images": {
                        "title": "Images",
                        "type": "array",
                        "description": "Array of images to resize. Each image can be provided as URL, base64, or Key-Value Store key.",
                        "items": {
                            "type": "object",
                            "properties": {
                                "url": {
                                    "title": "URL",
                                    "type": "string",
                                    "description": "Direct URL to the image",
                                    "editor": "textfield"
                                },
                                "base64": {
                                    "title": "Base64",
                                    "type": "string",
                                    "description": "Base64 encoded image data",
                                    "editor": "textarea"
                                },
                                "keyValueStoreKey": {
                                    "title": "Key-Value Store Key",
                                    "type": "string",
                                    "description": "Key in Apify Key-Value Store",
                                    "editor": "textfield"
                                },
                                "filename": {
                                    "title": "Filename",
                                    "type": "string",
                                    "description": "Optional filename for the output",
                                    "editor": "textfield"
                                }
                            }
                        }
                    },
                    "width": {
                        "title": "Width",
                        "minimum": 1,
                        "maximum": 10000,
                        "type": "integer",
                        "description": "Target width in pixels. Leave empty for auto-scaling based on height."
                    },
                    "height": {
                        "title": "Height",
                        "minimum": 1,
                        "maximum": 10000,
                        "type": "integer",
                        "description": "Target height in pixels. Leave empty for auto-scaling based on width."
                    },
                    "fit": {
                        "title": "Fit Mode",
                        "enum": [
                            "cover",
                            "contain",
                            "fill",
                            "inside",
                            "outside"
                        ],
                        "type": "string",
                        "description": "How the image should be resized to fit the dimensions.",
                        "default": "cover"
                    },
                    "position": {
                        "title": "Position",
                        "enum": [
                            "smart",
                            "center",
                            "top",
                            "bottom",
                            "left",
                            "right",
                            "left top",
                            "right top",
                            "left bottom",
                            "right bottom"
                        ],
                        "type": "string",
                        "description": "Position for cropping (when fit is 'cover'). Use 'smart' for intelligent face/subject detection.",
                        "default": "center"
                    },
                    "format": {
                        "title": "Output Format",
                        "enum": [
                            "jpeg",
                            "png",
                            "webp",
                            "tiff"
                        ],
                        "type": "string",
                        "description": "Output image format. Leave empty to keep original format."
                    },
                    "quality": {
                        "title": "Quality",
                        "minimum": 1,
                        "maximum": 100,
                        "type": "integer",
                        "description": "Output quality (1-100). Higher values mean better quality but larger file size.",
                        "default": 80
                    },
                    "outputFolder": {
                        "title": "Output Folder",
                        "type": "string",
                        "description": "Folder name in Key-Value Store for output images",
                        "default": "resized-images"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
