Krab logoKrab
API & Interfaces

Image URL to Base64

Provide an accessible image URL and return it converted to a Base64 Data URI.

Request

GETapi.krab.cn/api/image-to-base64

A publicly accessible image URL. Only http / https URLs are supported.

Query Parameters

ParameterTypeRequiredDescription
urlstringYesPublicly 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:

FieldTypeDescription
successbooleanWhether the request was successful
base64stringThe image's Base64 Data URI, in the format data:<mime>;base64,<payload>

Common Error Codes

HTTP Status CodecodeDescription
400INVALID_URLThe URL is empty, malformed, not http / https, or the domain cannot be resolved
400BLOCKED_HOSTThe URL points to a prohibited address such as localhost, a private-network IP, or a metadata IP
408FETCH_TIMEOUTImage download timed out
413IMAGE_TOO_LARGEThe image exceeds the size limit
415UNSUPPORTED_CONTENT_TYPEThe upstream returned content that is not an image
502FETCH_FAILEDUpstream image download failed, the status code is not 2xx, redirect handling failed, or there were too many redirects
Copyright © 2026 Krab. Some rights reserved.
Built with Docus.