# Image2svg

> Image2SVG transforms raster images into clean vector graphics, preserving visual quality while enabling scalable, customizable SVG outputs with precise control over detail levels.


## Overview

- **Endpoint**: `https://fal.run/fal-ai/image2svg`
- **Model ID**: `fal-ai/image2svg`
- **Category**: image-to-image
- **Kind**: inference
**Tags**: utility, editing



## Pricing

- **Price**: $0.005 per images

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`image_url`** (`string`, _required_):
  The image to convert to SVG
  - Examples: "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg"

- **`colormode`** (`ColormodeEnum`, _optional_):
  Choose between color or binary (black and white) output Default value: `"color"`
  - Default: `"color"`
  - Options: `"color"`, `"binary"`

- **`hierarchical`** (`HierarchicalEnum`, _optional_):
  Hierarchical mode: stacked or cutout Default value: `"stacked"`
  - Default: `"stacked"`
  - Options: `"stacked"`, `"cutout"`

- **`mode`** (`ModeEnum`, _optional_):
  Mode: spline (curved) or polygon (straight lines) Default value: `"spline"`
  - Default: `"spline"`
  - Options: `"spline"`, `"polygon"`

- **`filter_speckle`** (`integer`, _optional_):
  Filter out small speckles and noise Default value: `4`
  - Default: `4`
  - Range: `0` to `20`

- **`color_precision`** (`integer`, _optional_):
  Color quantization level Default value: `6`
  - Default: `6`
  - Range: `1` to `10`

- **`layer_difference`** (`integer`, _optional_):
  Layer difference threshold for hierarchical mode Default value: `16`
  - Default: `16`
  - Range: `1` to `32`

- **`corner_threshold`** (`integer`, _optional_):
  Corner detection threshold in degrees Default value: `60`
  - Default: `60`
  - Range: `0` to `180`

- **`length_threshold`** (`float`, _optional_):
  Length threshold for curves/lines Default value: `4`
  - Default: `4`
  - Range: `0` to `10`

- **`max_iterations`** (`integer`, _optional_):
  Maximum number of iterations for optimization Default value: `10`
  - Default: `10`
  - Range: `1` to `20`

- **`splice_threshold`** (`integer`, _optional_):
  Splice threshold for joining paths Default value: `45`
  - Default: `45`
  - Range: `0` to `90`

- **`path_precision`** (`integer`, _optional_):
  Decimal precision for path coordinates Default value: `3`
  - Default: `3`
  - Range: `1` to `10`



**Required Parameters Example**:

```json
{
  "image_url": "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg"
}
```

**Full Example**:

```json
{
  "image_url": "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg",
  "colormode": "color",
  "hierarchical": "stacked",
  "mode": "spline",
  "filter_speckle": 4,
  "color_precision": 6,
  "layer_difference": 16,
  "corner_threshold": 60,
  "length_threshold": 4,
  "max_iterations": 10,
  "splice_threshold": 45,
  "path_precision": 3
}
```


### Output Schema

The API returns the following output format:

- **`images`** (`list<File>`, _required_):
  The converted SVG file
  - Array of File
  - Examples: [{"file_size":1247850,"file_name":"output.svg","content_type":"image/svg+xml","url":"https://v3.fal.media/files/koala/B31yLkOEc6AVTzgeyr_9K_output.svg"}]



**Example Response**:

```json
{
  "images": [
    {
      "file_size": 1247850,
      "file_name": "output.svg",
      "content_type": "image/svg+xml",
      "url": "https://v3.fal.media/files/koala/B31yLkOEc6AVTzgeyr_9K_output.svg"
    }
  ]
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/image2svg \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "image_url": "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg"
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/image2svg",
    arguments={
        "image_url": "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg"
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/image2svg", {
  input: {
    image_url: "https://v3.fal.media/files/kangaroo/EfqY747bBKy1Ynrgbk5ba_04pwiD1LTsnMZuyEyw757_8f986248a89845d3ba90c23b14089f10.jpg"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/image2svg)
- [API Documentation](https://fal.ai/models/fal-ai/image2svg/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/image2svg)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
