# Vectorizing Images

Source: https://docs.prodia.com/guides/vectorizing-images/

Recraft V4 and V4 Pro can generate vector graphics (SVG) directly from text prompts. Unlike raster image generation which produces pixel-based output, vectorization produces infinitely scalable SVG files — perfect for logos, icons, illustrations, and print materials.

### Available models

| Job Type                              | Resolution      | ETA   |
| ------------------------------------- | --------------- | ----- |
| `inference.recraft.v4.txt2vec.v1`     | Up to 1536x768  | \~28s |
| `inference.recraft.v4.pro.txt2vec.v1` | Up to 3072x1536 | \~45s |

V4 Pro generates at higher resolution with more detail, but takes longer.

### Generate a vector image

### prodia-js

```javascript title="main.js"
import fs from "node:fs/promises";
import { createProdia } from "prodia/v2";

const prodia = createProdia({
  token: process.env.PRODIA_TOKEN,
});

const job = await prodia.job({
  type: "inference.recraft.v4.txt2vec.v1",
  config: {
    prompt: "a minimalist logo of a mountain range at sunset",
  },
});

const svg = await job.arrayBuffer();
await fs.writeFile("mountain.svg", new Uint8Array(svg));
console.log("Saved mountain.svg");
```

```bash
node main.js
```

### requests

```python title="main.py"
from requests.adapters import HTTPAdapter, Retry
import os
import requests
import sys

prodia_token = os.getenv('PRODIA_TOKEN')
prodia_url = 'https://inference.prodia.com/v2/job'

session = requests.Session()
retries = Retry(allowed_methods=None, status_forcelist=Retry.RETRY_AFTER_STATUS_CODES)
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))
session.headers.update({'Authorization': f"Bearer {prodia_token}"})

job = {
    'type': 'inference.recraft.v4.txt2vec.v1',
    'config': {
        'prompt': 'a minimalist logo of a mountain range at sunset',
    },
}

res = session.post(prodia_url, json=job)
print(f"Request ID: {res.headers['x-request-id']}")
print(f"Status: {res.status_code}")

if res.status_code != 200:
    print(res.text)
    sys.exit(1)

with open('mountain.svg', 'wb') as f:
    f.write(res.content)

print("Saved mountain.svg")
```

```bash
python main.py
```

### curl

```bash title="main.sh"
set -euo pipefail

job=$(cat <<EOF
{
  "type": "inference.recraft.v4.txt2vec.v1",
  "config": {
    "prompt": "a minimalist logo of a mountain range at sunset"
  }
}
EOF
)

curl -sSf \
  -H "Authorization: Bearer $PRODIA_TOKEN" \
  -H 'Accept: image/svg+xml' \
  --json "$job" \
  --output mountain.svg \
  --retry 3 \
  https://inference.prodia.com/v2/job
```

```bash
bash main.sh
```

### macOS

```bash
open mountain.svg
```

### Linux

```bash
xdg-open mountain.svg
```

### Windows

```bash
start mountain.svg
```

### Using V4 Pro for higher quality

Replace the job type with `inference.recraft.v4.pro.txt2vec.v1` for higher resolution output:

```javascript title="main.js"
const job = await prodia.job({
  type: "inference.recraft.v4.pro.txt2vec.v1",
  config: {
    prompt: "a minimalist logo of a mountain range at sunset",
    size: "2048x2048",
  },
});
```

### Controlling colors

Both models support a `controls` parameter to specify color palettes and background colors:

```javascript title="main.js"
const job = await prodia.job({
  type: "inference.recraft.v4.txt2vec.v1",
  config: {
    prompt: "a flat icon of a coffee cup",
    controls: {
      colors: [
        { rgb: [139, 90, 43] },
        { rgb: [255, 255, 255] },
      ],
      background_color: {
        rgb: [245, 245, 220],
      },
    },
  },
});
```

### Output format

The response is an SVG file. SVGs are XML-based vector graphics that:

- Scale to any size without quality loss
- Are typically 100KB–1MB depending on complexity
- Can be opened in any browser, Figma, Illustrator, or Inkscape
- Can be embedded directly in HTML with `<img src="output.svg">`

### Example outputs

**Recraft V4** (`inference.recraft.v4.txt2vec.v1`):

[Recraft V4 vector output — mountain landscape](https://docs.prodia.com/recraft-v4-txt2vec-output.svg)

**Recraft V4 Pro** (`inference.recraft.v4.pro.txt2vec.v1`):

[Recraft V4 Pro vector output — mountain landscape](https://docs.prodia.com/recraft-v4-pro-txt2vec-output.svg)

### Size options

**V4** (default: 1024x1024):

`1024x1024`, `1536x768`, `768x1536`, `1280x832`, `832x1280`, `1216x896`, `896x1216`, `1152x896`, `896x1152`, `832x1344`, `1280x896`, `896x1280`, `1344x768`, `768x1344`

**V4 Pro** (default: 2048x2048):

`2048x2048`, `3072x1536`, `1536x3072`, `2560x1664`, `1664x2560`, `2432x1792`, `1792x2432`, `2304x1792`, `1792x2304`, `1664x2688`, `2560x1792`, `1792x2560`, `2688x1536`, `1536x2688`
