# Cloudflare Images: Transform

Resize, crop, rotate, flip, blur, sharpen, recolor, compress, or format-convert an image from a URL using the Cloudflare Images binding. Returns the transformed image bytes (default WebP). Provide source_url plus any operations; with none it just re-encodes to the output format.

- Method: POST
- Path: `/images/transform`
- Price: $0.00300000

## Input Schema

```json
{
  "type": "object",
  "properties": {
    "source_url": {
      "type": "string",
      "format": "uri",
      "description": "Public URL of the source image to transform (max 15 MB)."
    },
    "width": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4096,
      "description": "Target width in pixels."
    },
    "height": {
      "type": "integer",
      "minimum": 1,
      "maximum": 4096,
      "description": "Target height in pixels."
    },
    "fit": {
      "type": "string",
      "enum": [
        "scale-down",
        "contain",
        "pad",
        "squeeze",
        "cover",
        "crop"
      ],
      "description": "How the image fits within width/height when both are set."
    },
    "gravity": {
      "type": "string",
      "enum": [
        "face",
        "left",
        "right",
        "top",
        "bottom",
        "center",
        "auto",
        "entropy"
      ],
      "description": "Focal point used when cropping."
    },
    "rotate": {
      "type": "number",
      "enum": [
        0,
        90,
        180,
        270
      ],
      "description": "Rotation in degrees."
    },
    "flip": {
      "type": "string",
      "enum": [
        "h",
        "v",
        "hv"
      ],
      "description": "Flip horizontally, vertically, or both."
    },
    "blur": {
      "type": "number",
      "minimum": 0,
      "maximum": 250,
      "description": "Gaussian blur radius (0-250)."
    },
    "sharpen": {
      "type": "number",
      "minimum": 0,
      "maximum": 10,
      "description": "Sharpen strength (0-10)."
    },
    "brightness": {
      "type": "number",
      "minimum": 0,
      "description": "Brightness multiplier (1 = unchanged)."
    },
    "contrast": {
      "type": "number",
      "minimum": 0,
      "description": "Contrast multiplier (1 = unchanged)."
    },
    "background": {
      "type": "string",
      "description": "Background color (e.g. \"#ffffff\") for pad/transparent areas."
    },
    "format": {
      "type": "string",
      "enum": [
        "webp",
        "avif",
        "jpeg",
        "png",
        "gif"
      ],
      "description": "Output format: webp (default), avif, jpeg, png, or gif."
    },
    "quality": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100,
      "description": "Output quality for lossy formats (1-100)."
    }
  },
  "required": [
    "source_url"
  ],
  "additionalProperties": false
}
```

## Output Schema

```json
{
  "type": "string",
  "format": "binary"
}
```

## Networks

| Name | Mode | CAIP-2 | Chain ID / Cluster | Protocols |
|---|---|---|---|---|
| Tempo Mainnet | live | `eip155:4217` | 4217 | mpp |
| Solana Mainnet | live | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` | mainnet-beta | mpp, x402 |
| Base | live | `eip155:8453` | 8453 | x402 |

## Accepted Currencies

| Symbol | Name | Decimals | Network | Address | Protocols |
|---|---|---|---|---|---|
| USDC.e | Bridged USDC (Stargate) | 6 | `eip155:4217` | `0x20c000000000000000000000b9537d11c60e8b50` | mpp |
| USDC | USD Coin (Solana) | 6 | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` | `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` | mpp, x402 |
| USDC | USD Coin | 6 | `eip155:8453` | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | x402 |

## How to invoke

Payment is handled automatically — the client signs the 402 challenge and retries.

### TypeScript — Tempo (mppx + fetch) ([docs](https://mpp.dev/sdk/typescript/client))

```ts
import { privateKeyToAccount } from 'viem/accounts'
import { Mppx, tempo } from 'mppx/client'

Mppx.create({
  methods: [tempo({ account: privateKeyToAccount('0x...') })],
})

const res = await fetch('https://cloudflare.payweave.services/images/transform', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "source_url": "https://example.com",
    "width": 1,
    "height": 1
  }),
})
const data = await res.json()
```

### TypeScript — Solana (@solana/mpp + fetch) ([docs](https://github.com/solana-foundation/mpp-sdk))

```ts
import { createKeyPairSignerFromBytes } from '@solana/kit'
import { Mppx } from 'mppx/client'
import { solana } from '@solana/mpp/client'

const signer = await createKeyPairSignerFromBytes(/* 64-byte secret key */)
Mppx.create({ methods: [solana({ signer })] })

const res = await fetch('https://cloudflare.payweave.services/images/transform', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "source_url": "https://example.com",
    "width": 1,
    "height": 1
  }),
})
const data = await res.json()
```

### mppx CLI ([docs](https://mpp.dev/sdk/typescript/cli))

```sh
npx mppx "https://cloudflare.payweave.services/images/transform" -X POST -H 'Content-Type: application/json' -d '{"source_url":"https://example.com","width":1,"height":1}'
```

### Tempo Wallet ([docs](https://docs.tempo.xyz/cli/wallet))

```sh
tempo request "https://cloudflare.payweave.services/images/transform" -X POST --json '{"source_url":"https://example.com","width":1,"height":1}'
```

### pay.sh — Solana Foundation ([docs](https://pay.sh))

```sh
pay --mainnet curl "https://cloudflare.payweave.services/images/transform" -X POST -H 'Content-Type: application/json' -d '{"source_url":"https://example.com","width":1,"height":1}'
```

### agentcash CLI ([docs](https://www.npmjs.com/package/agentcash))

```sh
npx agentcash fetch "https://cloudflare.payweave.services/images/transform" -m POST -b '{"source_url":"https://example.com","width":1,"height":1}' -p mpp
```

### x402 — Base / Solana USDC (x402-fetch) ([docs](https://x402.org))

```ts
import { wrapFetchWithPayment } from 'x402-fetch'
import { privateKeyToAccount } from 'viem/accounts'

const account = privateKeyToAccount('0x...') // Base USDC wallet
const fetchWithPay = wrapFetchWithPayment(fetch, account)

const res = await fetchWithPay('https://cloudflare.payweave.services/images/transform', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "source_url": "https://example.com",
    "width": 1,
    "height": 1
  }),
})
const data = await res.json()
```

### x402 — agentcash CLI

```sh
npx agentcash fetch "https://cloudflare.payweave.services/images/transform" -m POST -b '{"source_url":"https://example.com","width":1,"height":1}' -p x402
```
