# Image Crop and Rotate: Aspect Ratio, Box, Flip from URLs (`kotaro-project/image-crop-and-rotate`) Actor

Crop images at public URLs to an aspect ratio (1:1, 16:9, 4:5 and more) or an exact pixel box, rotate by any angle, flip horizontally or vertically, resize to a width, and save as JPEG, PNG or WebP with a download link. Pay per image; failed images are not charged.

- **URL**: https://apify.com/kotaro-project/image-crop-and-rotate.md
- **Developed by:** [KOTARO project](https://apify.com/kotaro-project) (community)
- **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 editeds

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 Crop and Rotate: Aspect Ratio, Box, Flip from URLs

Need square product shots, 16:9 banners or 9:16 story images from the same photos? Give this tool the image addresses and the shape you want.

### What it does

- **Crops** to an aspect ratio (1:1, 16:9, 9:16, 4:5 and more) keeping the centre or any side, or to an **exact pixel box**
- **Rotates** by any angle (90, 180 and 270 without loss)
- **Flips** left to right or top to bottom
- **Resizes** to a width and saves as **JPEG, PNG or WebP**
- Fixes phone photos that are stored sideways (EXIF orientation) before editing

### Input

```json
{
  "imageUrls": ["https://example.com/photo.jpg"],
  "aspectRatio": "1:1",
  "gravity": "center",
  "rotate": 0,
  "width": 1080
}
```

### Output

```json
{
  "imageUrl": "https://example.com/photo.jpg",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/.../records/edited-1a2b3c.jpg",
  "width": 1080,
  "height": 1080,
  "bytes": 183456
}
```

### Notes

- Order of work: crop, rotate, flip, resize.
- Up to 200 images per run, 50 MB each. Only public addresses are accepted.
- The sample input is Pillow's public-domain test photo of Grace Hopper (U.S. Navy).

### Pricing

Pay per edited image. Failed images are not charged. An empty run returns a free note.

# Actor input Schema

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

Public http(s) addresses of image files. Up to 200 per run, 50 MB each.

## `aspectRatio` (type: `string`):

Optional, for example 1:1, 16:9, 9:16 or 4:5. The largest area of that shape is kept.

## `gravity` (type: `string`):

When cropping to a ratio, which side of the image to keep.

## `cropBox` (type: `array`):

Optional \[x, y, width, height] in pixels from the top-left corner. Used instead of the aspect ratio.

## `rotate` (type: `number`):

Counter-clockwise angle. 90, 180 and 270 turn without losing any pixels; other angles enlarge the canvas.

## `fillColor` (type: `string`):

Colour of the new corners when rotating by an angle that is not a multiple of 90.

## `flipHorizontal` (type: `boolean`):

Mirror the image.

## `flipVertical` (type: `boolean`):

Turn the image upside down by mirroring.

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

Optional final width, keeping the ratio. 0 keeps the size.

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

same keeps JPEG, PNG or WebP; other formats are saved as PNG.

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

Higher keeps more detail and makes bigger files.

## Actor input object example

```json
{
  "imageUrls": [
    "https://raw.githubusercontent.com/python-pillow/Pillow/main/Tests/images/hopper.jpg"
  ],
  "aspectRatio": "16:9",
  "gravity": "center",
  "rotate": 0,
  "fillColor": "#ffffff",
  "flipHorizontal": false,
  "flipVertical": false,
  "width": 0,
  "format": "same",
  "quality": 90
}
```

# 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 = {
    "imageUrls": [
        "https://raw.githubusercontent.com/python-pillow/Pillow/main/Tests/images/hopper.jpg"
    ],
    "aspectRatio": "16:9"
};

// Run the Actor and wait for it to finish
const run = await client.actor("kotaro-project/image-crop-and-rotate").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": ["https://raw.githubusercontent.com/python-pillow/Pillow/main/Tests/images/hopper.jpg"],
    "aspectRatio": "16:9",
}

# Run the Actor and wait for it to finish
run = client.actor("kotaro-project/image-crop-and-rotate").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": [
    "https://raw.githubusercontent.com/python-pillow/Pillow/main/Tests/images/hopper.jpg"
  ],
  "aspectRatio": "16:9"
}' |
apify call kotaro-project/image-crop-and-rotate --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kotaro-project/image-crop-and-rotate"
        }
    }
}
```

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/NQm8dh3Gz9vdZ1qx8/builds/AOBW2dKNK8TxA0Zp0/openapi.json
