Converts binary image data into a Base64-encoded string.
Syntax
text AI_ImageAsBase64 (bytea image, boolean mime_type DEFAULT true)Parameters
Parameter | Description |
image | Image data in binary format. |
mime_type | Specifies whether the output Base64 string includes the Multipurpose Internet Mail Extensions (MIME) type prefix. Valid values:
Note For more information about MIME types, see the related community documentation. |
Return values
Returns a Base64-encoded string representation of the input image.
Description
This function currently supports the following image data formats: JPEG, PNG, and BMP.
In most cases, AI models have specific size requirements for input images. However, images in their original form may have high pixel dimensions, which can exceed the acceptable size for processing by the AI model. In this case, you can use the AI_ResizeImage function to resize the image to the required dimensions before using this function to convert it into a Base64 string.
Example
SELECT AI_ImageAsBase64(data) FROM ai_image_test WHERE id = 1;Sample output:
---
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD...