API & Interfaces
Image URL to Base64
Provide an accessible image URL and return it converted to a Base64 Data URI.
Request
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | Publicly accessible image URL. Only http / https are supported. |
curl Example
It is recommended to use --data-urlencode to avoid incorrect parsing of characters such as ?, &, and = inside the image URL.
curl -G 'https://api.krab.cn/api/image-to-base64' --data-urlencode 'url=https://zh.wikipedia.org/static/images/icons/wikipedia.png'
You can also directly access the URL-encoded address:
https://api.krab.cn/api/image-to-base64?url=https%3A%2F%2Fzh.wikipedia.org%2Fstatic%2Fimages%2Ficons%2Fwikipedia.png
Successful Response
{
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"success": true
}
Field descriptions:
| Field | Type | Description |
|---|---|---|
success | boolean | Whether the request was successful |
base64 | string | The image's Base64 Data URI, in the format data:<mime>;base64,<payload> |
Common Error Codes
| HTTP Status Code | code | Description |
|---|---|---|
| 400 | INVALID_URL | The URL is empty, malformed, not http / https, or the domain cannot be resolved |
| 400 | BLOCKED_HOST | The URL points to a prohibited address such as localhost, a private-network IP, or a metadata IP |
| 408 | FETCH_TIMEOUT | Image download timed out |
| 413 | IMAGE_TOO_LARGE | The image exceeds the size limit |
| 415 | UNSUPPORTED_CONTENT_TYPE | The upstream returned content that is not an image |
| 502 | FETCH_FAILED | Upstream image download failed, the status code is not 2xx, redirect handling failed, or there were too many redirects |